简体   繁体   中英

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.

I've tried to copy the request URL (after the string is built) and the browser gives me the expected answer.

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?

Thank you in advance.

First thing to check is the regional settings (1.2 vs 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/...", ...); 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM