问题
I am having a problem calling the mongohq REST API from a windows phone (7.1) application. I POSTing to a URL of the following form:
https://api.mongohq.com/databases/[database]/collections/[collection]/documents?_apikey=XXXXXXXXXXX
Exactly the same URL, when called from a browser-based REST client works for both GET and POST requests. But when I POST or GET to that URL from a windows phone app using either HttpWebRequest or WebClient, I get back a weird error that says simply "the server returned the response:'not found'". I have examined the database and collection in question via the mongohq website, and both are certainly present. I can also see the documents that have been added from browser REST client. A partial snippet of the exception I am getting is shown below.
Has anyone tried this before, or seem the same error in a similar context? Thanks in advance.
System.Net.WebException: The remote server returned an error: NotFound. ---> System.Net.WebException: The remote server returned an error: NotFound.
at System.Net.Browser.ClientHttpWebRequest.InternalEndGetResponse(IAsyncResult asyncResult)
at System.Net.Browser.ClientHttpWebRequest.<>c__DisplayClass2.<EndGetResponse>b__1(Object sendState)
at System.Net.Browser.AsyncHelper.<>c__DisplayClass4.<BeginOnUI>b__0(Object sendState)
at System.Reflection.RuntimeMethodInfo.InternalInvoke(RuntimeMethodInfo rtmi, Object obj, BindingFlags invokeAttr, Binder binder, Object parameters, CultureInfo culture, Boolean isBinderDefault, Assembly caller, Boolean verifyAccess, StackCrawlMark& stackMark)
at S
回答1:
You might try spoofing the User-Agent to be the same as a desktop browser and see if that makes a difference.
回答2:
I have similar problem (wp7.8). The solution is:
- Compile project to your device.
- Stop Debugging
- Close your app on phone (and better reboot device)
- All works like a charm))
It's help me (I used RestClient and WebClient)
I hope it's help you too.
Regards.
来源:https://stackoverflow.com/questions/14050739/not-found-error-calling-mongohq-rest-api-from-windows-phone