Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/323.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# HttpClient PostAsync参数不正确_C#_Windows_Visual Studio_Uwp - Fatal编程技术网

C# HttpClient PostAsync参数不正确

C# HttpClient PostAsync参数不正确,c#,windows,visual-studio,uwp,C#,Windows,Visual Studio,Uwp,我刚刚在我的Macbook Air上部署了Windows 10 64位教育,这是我的主开发PC上的一个稍微更新的安装程序,它也运行Windows 10 64位教育 我已经安装了Visual Studio 2017并下载了为我的项目解决方案打包的所有nugget,这正是我在我的开发PC上所做的 我的问题是,当我运行我们一直在内部使用的生产代码,并且没有收到客户的投诉时,它在我的新设置/安装中不起作用 我们有一种使用简单用户名和密码字段登录用户的方法。当我们调用PostAsync方法时,它会将表单数

我刚刚在我的Macbook Air上部署了Windows 10 64位教育,这是我的主开发PC上的一个稍微更新的安装程序,它也运行Windows 10 64位教育

我已经安装了Visual Studio 2017并下载了为我的项目解决方案打包的所有nugget,这正是我在我的开发PC上所做的

我的问题是,当我运行我们一直在内部使用的生产代码,并且没有收到客户的投诉时,它在我的新设置/安装中不起作用

我们有一种使用简单用户名和密码字段登录用户的方法。当我们调用PostAsync方法时,它会将表单数据发送到服务器。我用过邮递员,收到了正确的回复。代码根本没有被修改或更改,是已知的工作代码。我也在咖啡馆和家庭主妇那里工作,这是唯一的区别。我还没试着让这个在办公室工作。我们的客户去咖啡店,一直使用家庭wifi

如有任何想法和建议,将不胜感激

模糊异常-但我的代码根本没有更改?

{System.ArgumentException: The parameter is incorrect.
The parameter is incorrect.
at Windows.Web.Http.HttpClient.PostAsync(Uri uri, IHttpContent content)
at CoreProject.Helpers.LogginHelper.<UserLogin>d__1.MoveNext()}
HttpClient设置代码

Uri uri = new URI("https://oururi.com/login");
// disable caching
// https://social.msdn.microsoft.com/Forums/en-US/79e98534-5d8e-4879-acbe-7a457ee2a7ad/windowswebhttphttpclient-turn-off-caching?forum=winappswithcsharp
var RootFilter = new HttpBaseProtocolFilter();
RootFilter.CacheControl.ReadBehavior = HttpCacheReadBehavior.NoCache;
RootFilter.CacheControl.WriteBehavior = HttpCacheWriteBehavior.NoCache;

HttpClient httpClient = new HttpClient(RootFilter);
httpClient.DefaultRequestHeaders.Add("email", email);
httpClient.DefaultRequestHeaders.Add("pw", password);
httpClient.DefaultRequestHeaders.Add("apiVersion", "2.0");
httpClient.DefaultRequestHeaders.Add("version", CacheHelper.getVersionString());
httpClient.DefaultRequestHeaders.Add("appID", CacheHelper.Config.AppId());
httpClient.DefaultRequestHeaders.Add("platform", "windows");
httpClient.DefaultRequestHeaders.Add("updated", LocalSettingsHelper.GetContentLastUpdatedTimestamp());
httpClient.DefaultRequestHeaders.Add("bundleID", CacheHelper.Config.BundleId());
httpClient.DefaultRequestHeaders.Add("vendorID", Windows.System.UserProfile.AdvertisingManager.AdvertisingId);
httpClient.DefaultRequestHeaders.Add("deviceType", UtilityHelper.DeviceType());
httpClient.DefaultRequestHeaders.Add("osVersion", AnalyticsInfo.VersionInfo.DeviceFamilyVersion);

String termsValue = didAcceptTerms ? "1" : "0";
httpClient.DefaultRequestHeaders.Add("terms", termsValue);
return httpClient;
抛出异常的方法调用

 HttpResponseMessage response = await httpClient.PostAsync(uri, null);

你能告诉我们引发异常的ocde吗?我用一些codeHum更新了我的问题。。您的代码是正确的。Uri是正确的。传递null参数是正确的。检查传递
new StringContent()
而不是
null
是否有效。我使用的是
Windows.Web.Http
,因此
StringContent()
对我来说不兼容。
PostAsync
方法采用了一个
IHttpContent
参数,我并不清楚它的具体实现。但我也不确定我是否需要传递任何内容,因为它不是必需的。所以你是对的,这是一个空内容,但PostAsync应该处理这个问题