aow3xm
November 6, 2024, 3:27pm
1
Hello, I am facing a situation where I want to parse key - value as follows:
{
"origin": "https://nopecha.com",
"referer": "https://nopecha.com/?__cf_chl_tk=vMqjHc1Lm6ZjSYjnyC3j5zAXu3m30pcWi2fFjl.77MI-1730906641-1.0.1.1-oSZEUefxb3NxvMgdrsTdflBIxXnbKX0kEskXswzLF8I",
"upgrade-insecure-requests": "1",
"user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Safari/537.36",
"sec-ch-ua": "\"Chromium\";v=\"130\", \"Google Chrome\";v=\"130\", \"Not?A_Brand\";v=\"99\"",
"sec-ch-ua-arch": "\"x86\"",
"sec-ch-ua-bitness": "\"64\"",
"sec-ch-ua-full-version": "\"130.0.6723.92\"",
"sec-ch-ua-full-version-list": "\"Chromium\";v=\"130.0.6723.92\", \"Google Chrome\";v=\"130.0.6723.92\", \"Not?A_Brand\";v=\"99.0.0.0\"",
"sec-ch-ua-mobile": "?0",
"sec-ch-ua-model": "\"\"",
"sec-ch-ua-platform": "\"Windows\"",
"sec-ch-ua-platform-version": "\"15.0.0\"",
"accept-language": "en-US,en;q=0.9"
}
I want to parse the header and the corresponding values to attach them to the header for the request. Besides parsing each header individually, is there a way to parse all of them and attach them to the next request header in the format key: value, key2: value2?
Mrx001
November 6, 2024, 9:29pm
2
NameSpaces
System.Collections.Generic
Newtonsoft.Json
C# Code
BLOCK:ConstantString
value = "{ \"origin\": \"https://nopecha.com\", \"referer\": \"https://nopecha.com/?__cf_chl_tk=vMqjHc1Lm6ZjSYjnyC3j5zAXu3m30pcWi2fFjl.77MI-1730906641-1.0.1.1-oSZEUefxb3NxvMgdrsTdflBIxXnbKX0kEskXswzLF8I\", \"upgrade-insecure-requests\": \"1\", \"user-agent\": \"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Safari/537.36\", \"sec-ch-ua\": \"\\\"Chromium\\\";v=\\\"130\\\", \\\"Google Chrome\\\";v=\\\"130\\\", \\\"Not?A_Brand\\\";v=\\\"99\\\"\", \"sec-ch-ua-arch\": \"\\\"x86\\\"\", \"sec-ch-ua-bitness\": \"\\\"64\\\"\", \"sec-ch-ua-full-version\": \"\\\"130.0.6723.92\\\"\", \"sec-ch-ua-full-version-list\": \"\\\"Chromium\\\";v=\\\"130.0.6723.92\\\", \\\"Google Chrome\\\";v=\\\"130.0.6723.92\\\", \\\"Not?A_Brand\\\";v=\\\"99.0.0.0\\\"\", \"sec-ch-ua-mobile\": \"?0\", \"sec-ch-ua-model\": \"\\\"\\\"\", \"sec-ch-ua-platform\": \"\\\"Windows\\\"\", \"sec-ch-ua-platform-version\": \"\\\"15.0.0\\\"\", \"accept-language\": \"en-US,en;q=0.9\" }"
=> VAR @test
ENDBLOCK
string jsonString = test;
var dictionary = JsonConvert.DeserializeObject<Dictionary<string, string>>(jsonString);
BLOCK:HttpRequest
url = "https://www.google.com/"
readResponseContent = False
customHeaders = @dictionary
TYPE:STANDARD
$""
"application/x-www-form-urlencoded"
ENDBLOCK
1 Like
aow3xm
November 7, 2024, 2:16pm
3
Unfortunately, I use ob2 native and cannot modify C#.
Mrx001
November 7, 2024, 5:29pm
4
just paste it on the lolicode side
aow3xm
November 7, 2024, 7:00pm
5
thanks for the information