Я пытаюсь очистить веб-сайт для автоматизации загрузки отчета в формате .csv.Вот вызов ajax с веб-сайта, который я пытаюсь выполнить на стороне сервера в c #:
$.ajax(
{
url: '/my-folder/generate-report',
data: { model: JSON.stringify(data) },
type: 'POST',
dataType: "json",
success: function (response) { ... },
error: function (...) { ... }
);
Независимо от того, что я делаю, я получаю сообщение об ошибке «Значение не может быть нулевым.»
Сначала я должен зайти на сайт, который отлично работает.Затем я вызываю отчет-генерацию с использованием сообщения, и он всегда возвращает значение «Значение не может быть нулевым».
новый код ReportModel () не включен, но может быть при необходимости.По сути, он просто получает «данные» в точном формате, в котором он находится, когда я просматриваю заголовки Http при создании отчета через реальный веб-сайт / браузер.
Вот мой код c #:
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Net;
using System.Net.Http;
using System.Net.Http.Headers;
class ReportModel
{
public string SampleProperty1 => "SampleValue";
public string[] SampleArrayProperty1 => new string[] {};
}
class Program
{
static void Main(string[] args)
{
var baseAddress = new Uri("https://example.com");
var cookieContainer = new CookieContainer();
using (var handler = new HttpClientHandler() { CookieContainer = cookieContainer })
using (var client = new HttpClient(handler) { BaseAddress = baseAddress })
{
var homePageResult = client.GetAsync("/my-folder/");
homePageResult.Result.EnsureSuccessStatusCode();
var content = new FormUrlEncodedContent(new[]
{
new KeyValuePair<string, string>("UserName", "..."),
new KeyValuePair<string, string>("Password", "..."),
});
var loginResult = client.PostAsync("/my-folder/Login", content).Result;
loginResult.EnsureSuccessStatusCode();
var myContent = JsonConvert.SerializeObject(new ReportModel());
var buffer = System.Text.Encoding.UTF8.GetBytes(myContent);
var byteContent = new ByteArrayContent(buffer);
byteContent.Headers.ContentType = new MediaTypeHeaderValue("application/json");
var reportStep1Result = client.PostAsync("/my-folder/generate-report", byteContent);
reportStep1Result.Result.EnsureSuccessStatusCode();
var result = reportStep1Result.Result.Content.ReadAsStringAsync();
}
}
}
Приведенный выше результат показывает, что отчет не удалось сгенерировать, и сообщение выглядит следующим образом:
{
"Success":false,
"Message":"Value cannot be null.\r\nParameter name:value",
"Html":null,
"Model":null
}
Поскольку я знаю, что вызов ajax работает нормально при вызове из веб-приложения в браузере, ядумая, что я что-то упускаю при публикации вызова.
Когда я проверяю заголовок HTTP в Chrome Developer Tools (при вызове из браузера), я вижу заголовки> Данные формы> модель: {... представление jsonпараметров отчета ...}.
Возможно, я отправляю параметры json не так, как они отправляются в браузере?
Дайте мне знать, если вам нужна дополнительная информация, и я буду рад предоставить.Заранее спасибо.
Обновление от 04.12.2008 11:53 - добавлено больше подробностей в ReportModel, чтобы показать, как я его использую, просто как удобный способ сериализации в правильный JSON.
Обновление 4/4/2018 15:04 - подробности запроса при выполнении отчета в браузере:
"request": {
"method": "POST",
"url": "https://example.com/my-folder/generate-report",
"httpVersion": "HTTP/1.1",
"headers": [
{
"name": "Cookie",
"value": "_ga=...; SearchView=grid; HASH_SearchView=...; _gid=...; ASP.NET_SessionId=...; Emp_Id=...; TimeClockSessionKey=...; TimeClockEmp_Id=...; _gat_tracker1=1; _gat_tracker2=1; Expiration=12/4/2018 8:02:26 PM; SessionKey=..."
},
{
"name": "Origin",
"value": "https://example.com"
},
{
"name": "Accept-Encoding",
"value": "gzip, deflate, br"
},
{
"name": "Host",
"value": "example.com"
},
{
"name": "Accept-Language",
"value": "en-US,en;q=0.9"
},
{
"name": "User-Agent",
"value": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.110 Safari/537.36"
},
{
"name": "Content-Type",
"value": "application/x-www-form-urlencoded; charset=UTF-8"
},
{
"name": "Accept",
"value": "application/json, text/javascript, */*; q=0.01"
},
{
"name": "Referer",
"value": "https://example.com/my-folder/generate-report/"
},
{
"name": "X-Requested-With",
"value": "XMLHttpRequest"
},
{
"name": "Connection",
"value": "keep-alive"
},
{
"name": "Content-Length",
"value": "5385"
}
],
"queryString": [],
"cookies": [
{
"name": "_ga",
"value": "...",
"expires": null,
"httpOnly": false,
"secure": false
},
{
"name": "SearchView",
"value": "grid",
"expires": null,
"httpOnly": false,
"secure": false
},
{
"name": "HASH_SearchView",
"value": ".",..
"expires": null,
"httpOnly": false,
"secure": false
},
{
"name": "_gid",
"value": "...",
"expires": null,
"httpOnly": false,
"secure": false
},
{
"name": "ASP.NET_SessionId",
"value": "...",
"expires": null,
"httpOnly": false,
"secure": false
},
{
"name": "Emp_Id",
"value": "...",
"expires": null,
"httpOnly": false,
"secure": false
},
{
"name": "TimeClockSessionKey",
"value": "...",
"expires": null,
"httpOnly": false,
"secure": false
},
{
"name": "TimeClockEmp_Id",
"value": "...",
"expires": null,
"httpOnly": false,
"secure": false
},
{
"name": "_gat_tracker1",
"value": "1",
"expires": null,
"httpOnly": false,
"secure": false
},
{
"name": "_gat_tracker2",
"value": "1",
"expires": null,
"httpOnly": false,
"secure": false
},
{
"name": "Expiration",
"value": "12/4/2018 8:02:26 PM",
"expires": null,
"httpOnly": false,
"secure": false
},
{
"name": "SessionKey",
"value": "...",
"expires": null,
"httpOnly": false,
"secure": false
}
],
"headersSize": 1068,
"bodySize": 0,
"postData": {
"mimeType": "application/x-www-form-urlencoded; charset=UTF-8",
"text": "model=%7B%22LoggedInEmployeeId%22%3A%22%22%2C%22SelectedCompanyIds%22%3A%5B%221%22%5D%2C%22SelectedRouteCodes%22%3A%5B%22NULL%22%2C%22R01%22%5D%2C%22SelectedTerritoryCodes%22%3A%5B%5D%2C%22SelectedZipCodes%22%3A%5B%2260137%22%2C%2260148%22%2C%2260174%22%2C%2260181%22%2C%2260187%22%2C%2260189%22%2C%2260190%22%2C%2260403%22%2C%2260404%22%2C%2260410%22%2C%2260431%22%2C%2260432%22%2C%2260433%22%2C%2260435%22%2C%2260436%22%2C%2260439%22%2C%2260440%22%2C%2260441%22%2C%2260446%22%2C%2260447%22%2C%2260451%22%2C%2260467%22%2C%2260490%22%2C%2260491%22%2C%2260502%22%2C%2260503%22%2C%2260504%22%2C%2260505%22%2C%2260506%22%2C%2260510%22%2C%2260512%22%2C%2260514%22%2C%2260515%22%2C%2260516%22%2C%2260517%22%2C%2260532%22%2C%2260538%22%2C%2260540%22%2C%2260543%22%2C%2260544%22%2C%2260545%22%2C%2260551%22%2C%2260554%22%2C%2260555%22%2C%2260559%22%2C%2260560%22%2C%2260561%22%2C%2260563%22%2C%2260564%22%2C%2260565%22%2C%2260585%22%2C%2260586%22%2C%2299999%22%5D%2C%22SelectedSourceCodes%22%3A%5B%22-1%22%2C%22105%22%2C%2279%22%2C%2285%22%2C%2274%22%2C%2248%22%2C%22112%22%2C%22119%22%2C%22125%22%2C%2293%22%2C%22130%22%2C%2269%22%2C%2263%22%2C%22127%22%2C%2266%22%2C%2265%22%2C%2256%22%2C%228%22%2C%2247%22%2C%2276%22%2C%2290%22%2C%22123%22%2C%2282%22%2C%2294%22%2C%22124%22%2C%2258%22%2C%2271%22%2C%22107%22%2C%2255%22%2C%22101%22%2C%22102%22%2C%22132%22%2C%22122%22%2C%22118%22%2C%2273%22%2C%2254%22%2C%2253%22%2C%2250%22%2C%2284%22%2C%2218%22%2C%2223%22%2C%2243%22%2C%2283%22%2C%2236%22%2C%2224%22%2C%2230%22%2C%2226%22%2C%2233%22%2C%2232%22%2C%2231%22%2C%2277%22%2C%22128%22%2C%2217%22%2C%22115%22%2C%22106%22%2C%22111%22%2C%22113%22%2C%2251%22%2C%2297%22%2C%2299%22%2C%2298%22%2C%2296%22%2C%2245%22%2C%2295%22%2C%22108%22%2C%22121%22%2C%2249%22%2C%22126%22%2C%22114%22%2C%22117%22%2C%2292%22%2C%2281%22%2C%2260%22%2C%2212%22%2C%2222%22%2C%2211%22%2C%2235%22%2C%2237%22%2C%22116%22%2C%2210%22%2C%22131%22%2C%2288%22%2C%2289%22%2C%2219%22%2C%2234%22%2C%229%22%2C%2278%22%2C%2264%22%2C%2244%22%2C%2280%22%2C%2275%22%2C%2286%22%2C%2259%22%2C%2270%22%2C%22129%22%2C%2291%22%2C%22100%22%2C%22120%22%2C%22103%22%2C%2246%22%2C%2240%22%2C%2225%22%2C%2261%22%2C%22109%22%2C%2242%22%2C%2252%22%2C%2241%22%2C%2228%22%2C%22133%22%2C%22110%22%2C%227%22%2C%2257%22%2C%2262%22%2C%2287%22%2C%22104%22%5D%2C%22SelectedBillingTypes%22%3A%5B%22R%22%2C%22M%22%2C%22A%22%2C%22D%22%2C%22C%22%5D%2C%22SelectedCustomerStatuses%22%3A%5B%228%22%2C%229%22%5D%2C%22SelectedTaxCodes%22%3A%5B%5D%2C%22CustomerType%22%3A%22Both%22%2C%22BillToOption%22%3A%22All%22%2C%22Season%22%3A%222018%22%2C%22SelectedPropertyInventory%22%3A%220%22%2C%22StartDate%22%3A%221753-01-01+00%3A00%3A00%22%2C%22EndDate%22%3A%229998-12-31+23%3A59%3A59%22%2C%22DateRangeText%22%3A%22All%22%2C%22BeginCustomerNumberRange%22%3A%220%22%2C%22EndCustomerNumberRange%22%3A%22999999999%22%2C%22BeginMapcodeRange%22%3A%22%22%2C%22EndMapcodeRange%22%3A%22ZZ-ZZ-ZZZ%22%2C%22BeginCarrierRouteRange%22%3A%22%22%2C%22EndCarrierRouteRange%22%3A%22ZZZZ%22%2C%22BeginSizeRange%22%3A%220%22%2C%22EndSizeRange%22%3A%229999999.99%22%2C%22IncludeCustomersWithoutServices%22%3A%22true%22%2C%22SelectedSortOrder%22%3A%22CustomerNumber%22%2C%22SummaryOnly%22%3A%22false%22%2C%22PreviewFlag%22%3A%22false%22%2C%22SelectedFlags%22%3A%22%7B%5C%22with%5C%22%3A%5B%5D%2C%5C%22without%5C%22%3A%5B%5D%7D%22%2C%22AdvanceOptionsDataAsString%22%3A%22%7B%5C%22CustomerPhone%5C%22%3A0%2C%5C%22CustomerEmail%5C%22%3A0%2C%5C%22CustomerCreditHold%5C%22%3A0%2C%5C%22GroupBillingMasterAccounts%5C%22%3A%5B%5D%2C%5C%22WithDocuments%5C%22%3A%5B%5D%2C%5C%22WithoutDocuments%5C%22%3A%5B%5D%2C%5C%22DocumentsStartDate%5C%22%3A%5C%2201%2F01%2F2018%5C%22%2C%5C%22DocumentsEndDate%5C%22%3A%5C%2212%2F31%2F2018%5C%22%2C%5C%22DocumentsDateName%5C%22%3A%5C%22This+year%5C%22%2C%5C%22WithLetters%5C%22%3A%5B%5D%2C%5C%22WithoutLetters%5C%22%3A%5B%5D%2C%5C%22LettersStartDate%5C%22%3A%5C%2201%2F01%2F2018%5C%22%2C%5C%22LettersEndDate%5C%22%3A%5C%2212%2F31%2F2018%5C%22%2C%5C%22LettersDateName%5C%22%3A%5C%22This+year%5C%22%2C%5C%22WithNPS%5C%22%3A%5B%5D%2C%5C%22WithoutNPS%5C%22%3A%5B%5D%2C%5C%22NPSStartDate%5C%22%3A%5C%2201%2F01%2F2018%5C%22%2C%5C%22NPSEndDate%5C%22%3A%5C%2212%2F31%2F2018%5C%22%2C%5C%22NPSDateName%5C%22%3A%5C%22This+year%5C%22%2C%5C%22DontTelemarket%5C%22%3A%5C%220%5C%22%2C%5C%22DontDirectMail%5C%22%3A%5C%220%5C%22%2C%5C%22DontEmail%5C%22%3A%5C%220%5C%22%2C%5C%22DontFollowupByEmail%5C%22%3A%5C%220%5C%22%2C%5C%22DontUpsell%5C%22%3A%5C%220%5C%22%2C%5C%22NoKnock%5C%22%3A%5C%220%5C%22%2C%5C%22CawRegisteredUser%5C%22%3A%5C%220%5C%22%2C%5C%22AutoPay%5C%22%3A%5C%220%5C%22%2C%5C%22PreferredLanguage%5C%22%3A%5C%220%5C%22%2C%5C%22EmailStatements%5C%22%3A%5C%220%5C%22%2C%5C%22EmailPrenotification%5C%22%3A%5C%220%5C%22%2C%5C%22TextPrenotification%5C%22%3A%5C%220%5C%22%2C%5C%22WithContactPreferred%5C%22%3A%5B%5D%2C%5C%22WithoutContactPreferred%5C%22%3A%5B%5D%2C%5C%22WithSourceSize%5C%22%3A%5B%5D%2C%5C%22WithoutSourceSize%5C%22%3A%5B%5D%2C%5C%22WithSubdivisions%5C%22%3A%5B%5D%2C%5C%22WithoutSubdivisions%5C%22%3A%5B%5D%7D%22%2C%22SendToCallLog%22%3A%22false%22%2C%22SendToCallLogData%22%3Anull%2C%22MainGrouping%22%3A%22Ignore%22%2C%22SubGrouping%22%3A%22Ignore%22%2C%22AllRouteCodes%22%3A%22true%22%2C%22AllSourceCodes%22%3A%22false%22%2C%22AllZipCodes%22%3A%22true%22%2C%22AllTerritoryCodes%22%3A%22true%22%2C%22AllTaxCodes%22%3A%22true%22%2C%22ExportToCSV%22%3Atrue%7D",
"params": [
{
"name": "model",
"value": "%7B%22LoggedInEmployeeId%22%3A%22%22%2C%22SelectedCompanyIds%22%3A%5B%221%22%5D%2C%22SelectedRouteCodes%22%3A%5B%22NULL%22%2C%22R01%22%5D%2C%22SelectedTerritoryCodes%22%3A%5B%5D%2C%22SelectedZipCodes%22%3A%5B%2260137%22%2C%2260148%22%2C%2260174%22%2C%2260181%22%2C%2260187%22%2C%2260189%22%2C%2260190%22%2C%2260403%22%2C%2260404%22%2C%2260410%22%2C%2260431%22%2C%2260432%22%2C%2260433%22%2C%2260435%22%2C%2260436%22%2C%2260439%22%2C%2260440%22%2C%2260441%22%2C%2260446%22%2C%2260447%22%2C%2260451%22%2C%2260467%22%2C%2260490%22%2C%2260491%22%2C%2260502%22%2C%2260503%22%2C%2260504%22%2C%2260505%22%2C%2260506%22%2C%2260510%22%2C%2260512%22%2C%2260514%22%2C%2260515%22%2C%2260516%22%2C%2260517%22%2C%2260532%22%2C%2260538%22%2C%2260540%22%2C%2260543%22%2C%2260544%22%2C%2260545%22%2C%2260551%22%2C%2260554%22%2C%2260555%22%2C%2260559%22%2C%2260560%22%2C%2260561%22%2C%2260563%22%2C%2260564%22%2C%2260565%22%2C%2260585%22%2C%2260586%22%2C%2299999%22%5D%2C%22SelectedSourceCodes%22%3A%5B%22-1%22%2C%22105%22%2C%2279%22%2C%2285%22%2C%2274%22%2C%2248%22%2C%22112%22%2C%22119%22%2C%22125%22%2C%2293%22%2C%22130%22%2C%2269%22%2C%2263%22%2C%22127%22%2C%2266%22%2C%2265%22%2C%2256%22%2C%228%22%2C%2247%22%2C%2276%22%2C%2290%22%2C%22123%22%2C%2282%22%2C%2294%22%2C%22124%22%2C%2258%22%2C%2271%22%2C%22107%22%2C%2255%22%2C%22101%22%2C%22102%22%2C%22132%22%2C%22122%22%2C%22118%22%2C%2273%22%2C%2254%22%2C%2253%22%2C%2250%22%2C%2284%22%2C%2218%22%2C%2223%22%2C%2243%22%2C%2283%22%2C%2236%22%2C%2224%22%2C%2230%22%2C%2226%22%2C%2233%22%2C%2232%22%2C%2231%22%2C%2277%22%2C%22128%22%2C%2217%22%2C%22115%22%2C%22106%22%2C%22111%22%2C%22113%22%2C%2251%22%2C%2297%22%2C%2299%22%2C%2298%22%2C%2296%22%2C%2245%22%2C%2295%22%2C%22108%22%2C%22121%22%2C%2249%22%2C%22126%22%2C%22114%22%2C%22117%22%2C%2292%22%2C%2281%22%2C%2260%22%2C%2212%22%2C%2222%22%2C%2211%22%2C%2235%22%2C%2237%22%2C%22116%22%2C%2210%22%2C%22131%22%2C%2288%22%2C%2289%22%2C%2219%22%2C%2234%22%2C%229%22%2C%2278%22%2C%2264%22%2C%2244%22%2C%2280%22%2C%2275%22%2C%2286%22%2C%2259%22%2C%2270%22%2C%22129%22%2C%2291%22%2C%22100%22%2C%22120%22%2C%22103%22%2C%2246%22%2C%2240%22%2C%2225%22%2C%2261%22%2C%22109%22%2C%2242%22%2C%2252%22%2C%2241%22%2C%2228%22%2C%22133%22%2C%22110%22%2C%227%22%2C%2257%22%2C%2262%22%2C%2287%22%2C%22104%22%5D%2C%22SelectedBillingTypes%22%3A%5B%22R%22%2C%22M%22%2C%22A%22%2C%22D%22%2C%22C%22%5D%2C%22SelectedCustomerStatuses%22%3A%5B%228%22%2C%229%22%5D%2C%22SelectedTaxCodes%22%3A%5B%5D%2C%22CustomerType%22%3A%22Both%22%2C%22BillToOption%22%3A%22All%22%2C%22Season%22%3A%222018%22%2C%22SelectedPropertyInventory%22%3A%220%22%2C%22StartDate%22%3A%221753-01-01+00%3A00%3A00%22%2C%22EndDate%22%3A%229998-12-31+23%3A59%3A59%22%2C%22DateRangeText%22%3A%22All%22%2C%22BeginCustomerNumberRange%22%3A%220%22%2C%22EndCustomerNumberRange%22%3A%22999999999%22%2C%22BeginMapcodeRange%22%3A%22%22%2C%22EndMapcodeRange%22%3A%22ZZ-ZZ-ZZZ%22%2C%22BeginCarrierRouteRange%22%3A%22%22%2C%22EndCarrierRouteRange%22%3A%22ZZZZ%22%2C%22BeginSizeRange%22%3A%220%22%2C%22EndSizeRange%22%3A%229999999.99%22%2C%22IncludeCustomersWithoutServices%22%3A%22true%22%2C%22SelectedSortOrder%22%3A%22CustomerNumber%22%2C%22SummaryOnly%22%3A%22false%22%2C%22PreviewFlag%22%3A%22false%22%2C%22SelectedFlags%22%3A%22%7B%5C%22with%5C%22%3A%5B%5D%2C%5C%22without%5C%22%3A%5B%5D%7D%22%2C%22AdvanceOptionsDataAsString%22%3A%22%7B%5C%22CustomerPhone%5C%22%3A0%2C%5C%22CustomerEmail%5C%22%3A0%2C%5C%22CustomerCreditHold%5C%22%3A0%2C%5C%22GroupBillingMasterAccounts%5C%22%3A%5B%5D%2C%5C%22WithDocuments%5C%22%3A%5B%5D%2C%5C%22WithoutDocuments%5C%22%3A%5B%5D%2C%5C%22DocumentsStartDate%5C%22%3A%5C%2201%2F01%2F2018%5C%22%2C%5C%22DocumentsEndDate%5C%22%3A%5C%2212%2F31%2F2018%5C%22%2C%5C%22DocumentsDateName%5C%22%3A%5C%22This+year%5C%22%2C%5C%22WithLetters%5C%22%3A%5B%5D%2C%5C%22WithoutLetters%5C%22%3A%5B%5D%2C%5C%22LettersStartDate%5C%22%3A%5C%2201%2F01%2F2018%5C%22%2C%5C%22LettersEndDate%5C%22%3A%5C%2212%2F31%2F2018%5C%22%2C%5C%22LettersDateName%5C%22%3A%5C%22This+year%5C%22%2C%5C%22WithNPS%5C%22%3A%5B%5D%2C%5C%22WithoutNPS%5C%22%3A%5B%5D%2C%5C%22NPSStartDate%5C%22%3A%5C%2201%2F01%2F2018%5C%22%2C%5C%22NPSEndDate%5C%22%3A%5C%2212%2F31%2F2018%5C%22%2C%5C%22NPSDateName%5C%22%3A%5C%22This+year%5C%22%2C%5C%22DontTelemarket%5C%22%3A%5C%220%5C%22%2C%5C%22DontDirectMail%5C%22%3A%5C%220%5C%22%2C%5C%22DontEmail%5C%22%3A%5C%220%5C%22%2C%5C%22DontFollowupByEmail%5C%22%3A%5C%220%5C%22%2C%5C%22DontUpsell%5C%22%3A%5C%220%5C%22%2C%5C%22NoKnock%5C%22%3A%5C%220%5C%22%2C%5C%22CawRegisteredUser%5C%22%3A%5C%220%5C%22%2C%5C%22AutoPay%5C%22%3A%5C%220%5C%22%2C%5C%22PreferredLanguage%5C%22%3A%5C%220%5C%22%2C%5C%22EmailStatements%5C%22%3A%5C%220%5C%22%2C%5C%22EmailPrenotification%5C%22%3A%5C%220%5C%22%2C%5C%22TextPrenotification%5C%22%3A%5C%220%5C%22%2C%5C%22WithContactPreferred%5C%22%3A%5B%5D%2C%5C%22WithoutContactPreferred%5C%22%3A%5B%5D%2C%5C%22WithSourceSize%5C%22%3A%5B%5D%2C%5C%22WithoutSourceSize%5C%22%3A%5B%5D%2C%5C%22WithSubdivisions%5C%22%3A%5B%5D%2C%5C%22WithoutSubdivisions%5C%22%3A%5B%5D%7D%22%2C%22SendToCallLog%22%3A%22false%22%2C%22SendToCallLogData%22%3Anull%2C%22MainGrouping%22%3A%22Ignore%22%2C%22SubGrouping%22%3A%22Ignore%22%2C%22AllRouteCodes%22%3A%22true%22%2C%22AllSourceCodes%22%3A%22false%22%2C%22AllZipCodes%22%3A%22true%22%2C%22AllTerritoryCodes%22%3A%22true%22%2C%22AllTaxCodes%22%3A%22true%22%2C%22ExportToCSV%22%3Atrue%7D"
}
]
}
},
Обновление 4/4/2018 15:48 - я изменяю код на URLзакодируйте JSON перед его передачей:
var myContent = HttpUtility.UrlEncode(JsonConvert.SerializeObject(new model()));
var formUrlEncodedContent = new FormUrlEncodedContent(new[] { new KeyValuePair<string, string>("model", myContent) });
var reportStep1Result = client.PostAsync("/my-folder/generate-report", formUrlEncodedContent);
reportStep1Result.Result.EnsureSuccessStatusCode();
var result = reportStep1Result.Result.Content.ReadAsStringAsync();
Вот новая ошибка, которую я получаю:
{
"Success":false,
"Message":"Unexpected character encountered while parsing value: %. Path '', line 0, position 0.",
"Html":null,
"Model":null
}
Как получается, что закодированный JSON URL дважды появляется в запросе?Как только он отображается в качестве значения для «текста» и имеет префикс модели = и снова в массиве «параметров» в качестве параметра «значение» без префикса модели =?
Обновление от 04.12.2008 4:15:00 - Отслеживание с помощью Fiddler показывает:
Проверка с помощью Fiddler, когда я вызываю его из c #, показывает следующее:
POST
https://example.com/my-folder/generate-report HTTP/1.1
Content-Type: application/x-www-form-urlencoded
Host: example.com
Cookie: ASP.NET_SessionId=...;
SessionKey=...;
Emp_Id=...;
Expiration=12/4/2018 11:57:38 PM;
TimeClockSessionKey=...;
TimeClockEmp_Id=JJB
Content-Length: 7658
Expect: 100-continue
model=%257b%2522LoggedInEmployeeId%2522...
Обратите внимание, что версия Fiddler начинается с% 25.Браузер запускается с% 7b.% 25 - это кодировка URL% - так что кажется, что он получает кодировку URL 2x.Я изменю его на StringContent вместо FormUrlEncodedContent и вручную закодирую только JSON и посмотрю, работает ли это ...
Я исправил эту проблему с помощью кодировки двойных URL.Теперь модель одинакова как для веб-браузера, так и для вызовов c #.Все еще получаю ошибку.Заголовки отличаются между 2. Чем-то выделяется ??
ЖАТКА ИЗ КОНСОЛЬНОГО ПРИЛОЖЕНИЯ C #:
POST
https://example.com/my-folder/generate-report HTTP/1.1
Content-Type: application/x-www-form-urlencoded
Host: example.com
Cookie: ASP.NET_SessionId=...;
SessionKey=...;
Emp_Id=...;
Expiration=12/5/2018 3:04:35 AM;
TimeClockSessionKey=...;
TimeClockEmp_Id=...
Content-Length: 5386
Expect: 100-continue
ЖАТКА ИЗ БРАУЗЕРА:
POST https://example.com/my-folder/generate-report HTTP/1.1
Host: example.com
Connection: keep-alive
Content-Length: 5385
Accept: application/json, text/javascript, */*; q=0.01
Origin: https://example.com
X-Requested-With: XMLHttpRequest
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.110 Safari/537.36
Content-Type: application/x-www-form-urlencoded; charset=UTF-8
Referer: https://example.com/my-folder/generate-report/
Accept-Encoding: gzip, deflate, br
Accept-Language: en-US,en;q=0.9
Cookie: _ga=...;
SearchView=grid;
HASH_SearchView=...;
_gid=...;
ASP.NET_SessionId=...;
LoginRedirectTo=https%3A%2F%2Fexample.com%2Fmy-folder%2Fgenerate-report%2F;
_gat_tracker1=1;
_gat_tracker2=1;
Emp_Id=...;
TimeClockSessionKey=...;
TimeClockEmp_Id=...;
Expiration=12/5/2018 3:06:22 AM;
SessionKey=...