Dictionary<string, string> headers = new Dictionary<string, string>();
headers.Add("user-agent","mozilla");
headers.Add("pragma","no-cache");
headers.Add("referer","google.com");
import requests
headers = {сюда вставить содержимое словаря}
response = requests.get('test.com',headers=headers)
import requests
headers = {'user-agent':'mozilla',
'pragma':'no-cache',
'referer':'google.com'}
response = requests.get('test.com',headers=headers)
public static string PythonRequestTemplate(string headers)
{
var template = $@"import requests
headers = {{ {
headers
} }}
response = requests.get('test.com', headers = headers)";
return template;
}
var headers = new Dictionary<string, string>();
headers.Add("user-agent", "mozilla");
headers.Add("pragma", "no-cache");
headers.Add("referer", "google.com");
Console.WriteLine(PythonRequestTemplate(headers.Select(item => item.Key + ":" + item.Value).Aggregate((item1, item2) => item1 + ",\n" + item2)));
using System;
using System.Collections.Generic;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Newtonsoft.Json.Converters;
using Newtonsoft.Json.Serialization;
Dictionary<string, string> headers = new Dictionary<string, string>();
headers.Add("user-agent","mozilla");
headers.Add("pragma","no-cache");
headers.Add("referer","google.com");
var jsonString = JsonConvert.SerializeObject(headers);
Console.WriteLine(jsonString); // {"user-agent":"mozilla","pragma":"no-cache","referer":"google.com"}