简体   繁体   English

为什么HttpRequest不能在Windows上运行但在Mac上运行?

[英]Why does HttpRequest not work on Windows but works on Mac?

My partner who uses a Mac can run the program without any problem but when I try to run it it gives WebException: The remote server returned an error: (400) Bad Request. 我使用Mac的合作伙伴可以毫无问题地运行程序,但是当我尝试运行它时,它会产生WebException: The remote server returned an error: (400) Bad Request.

I've tried to copy the request URL (after the string is built) and the browser gives me the expected answer. 我试图复制请求URL(在构建字符串之后),浏览器给出了预期的答案。

The code is this: 代码是这样的:

double SearchLatitude = 41.480687;
double SearchLongitude = -8.527346;
double Radius = 10; // km  
int maxResults = 5;
string bingMapsKey = "MyKey";
string requestUrl = string.Format("http://spatial.virtualearth.net/REST/v1/data/c2ae584bbccc4916a0acf75d1e6947b4/NavteqEU/NavteqPOIs" +
            "?spatialFilter=nearby({0},{1},{2})&$filter=EntityTypeID Eq 5400&$top={3}&key={4}", SearchLatitude, SearchLongitude, Radius, maxResults,bingMapsKey);

HttpWebRequest request = WebRequest.Create(requestUrl) as HttpWebRequest;
HttpWebResponse response = request.GetResponse() as HttpWebResponse; 

Can this be a Windows problem? 这可能是Windows问题吗?

Thank you in advance. 先感谢您。

First thing to check is the regional settings (1.2 vs 1,2). 首先要检查的是区域设置(1.2对1,2)。

And always best to use 总是最好用

//string requestUrl = string.Format("http://spatial.virtualearth.net/REST/...", ...);
  string requestUrl = string.Format(CultureInfo.InvariantCulture, "http://spatial.virtualearth.net/REST/...", ...); 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 .net 内核中的 HttpRequest.Query[] 是如何工作的? - How does HttpRequest.Query[] in .net core works? C#中的NetworkCredential在分配给HttpRequest对象时如何工作? - How does NetworkCredential in C# works when assigned to a HttpRequest object? 代码在控制台应用程序中有效,但在Windows Service中运行时不起作用 - Code works in a console application, but does not work when running in windows service System.Windows.Forms.Clipboard 适用于桌面,但不适用于 IIS - System.Windows.Forms.Clipboard works on desktop, but does not work on IIS System.Web.HttpRequest::PathInfo 如何工作? - how does System.Web.HttpRequest::PathInfo work? 为什么此代码适用于Windows 7,但不适用于Windows XP? - Why does this code work on Windows 7, but doesn't on Windows XP? 为什么 ConfigureAwait(false) 在 Task.Run() 工作时不起作用? - Why ConfigureAwait(false) does not work while Task.Run() works? 为什么更改HttpRequest中的Host标头会影响服务器响应? - Why does changing the Host header in HttpRequest affect server response? 为什么控制器动作有HttpRequestBase,而viewpage有HttpRequest? - why does the controllers action have HttpRequestBase, and the viewpage has HttpRequest? 为什么使用 DataDirectory 不起作用但使用完整路径有效? - Why does using DataDirectory not work but using a full path works?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM