sometimes the webrequest just returns null and yet when i click the button to do the request again it works fine…this does not happen all the time but enough that it is annoying, is there something wrong with my code??
This is unlikely your problem, but UnityWebRequest implements the IDisposable interface, which means you should probably stick it in a using() block.
Also, try other endpoints than the one URL. Also, are you seeing any errors? If you build to device, are you seeing any exceptions such as SSL exceptions?
It’s also possible that your server doesn’t like whatever your “gcid” value is. Do you have server logs for the requests that return null? What was the server’s response in those cases?
Also, presumably “url” is just a string you’re using on the forums and not what’s actually in your code right?
yeah the addfield gcid and url are just placeholders… There are no errors in the log at all…it just returns null. it has happened when using multiple urls and as i said does not happen all the time but just some times, really not sure what the problem is and why it only happens sometimes and not all the time.
The same thing is still happening however what I find very interesting is it only happens if you try and send a request around the 2 second mark of the first one returning…If you click the button to send <2 seconds it works fine…if you wait for about 4 seconds or more it works fine…if you wait approx 2 seconds and send it, it Always comes back blank…
this behaviour is really strange btw, you should try with another entirely different post request that you know is guaranteed to work and see if it behaves the same
It seems to happen with all request, i have made multiple now and they all seem to fail at some time or another, the way i go around it was to duplicate the IEnumerator function and call it webrequestcall2, when webrequest call returns null it immediately starts coroutine for webrequestcall2 and that one works. I gave up on trying to fix the problem, absolutely no idea what is causing it, i have tried calling dispose and using the using() block. All seem to fail maybe 1 in 20 times always around the 2 second mark of the 1st coroutine returning from the server.
Does it look like request was successful but no data returned?
If so, setup HTTP debugging proxy (such as Fiddler) and examine the request/response of the failed one.
If the error is something else, paste the contents from the console.
there is no error in the logs at all, I did play around with the other values to see what was happening, if i try and debug.log the returndata the app just hangs however if you just check it is null then the app continues.
I also tried logging getresponseheaders and it received 2 headers when the webrequest succeeded but none when the value returned null. It seems almost like unity is cancelling the request before it even reaches the server and just returning a null value.
I will look into fiddler later on and see if that can show anything.
What is null?
The error you describe is a symptom of using UWR after it has been disposed, which would mean an error in your code. Can’t tell exactly without knowing what your actual code looks like exactly.
no error in console at all
string returndata = www.downloadHandler.text;
returndata just returns null as in nothing there…i even added a line on the server error_log to log everytime it hits the server and when it returns null it doesn’t even reach the server. I will test later on with another url and see if the error persists but it errors so fast that it seems like it doesn’t even have time for the data to get to my server before it returns null in www.downloadHandler.text
When www.downloadhandler.text returned null the response headers were also null as in nothing in them, when the request worked fine the response headers had a dictionary with 2 strings in them.
That sounds low. Normally there are much more headers. What is your server setup?
You certainly need to setup Fiddler or similar and examine the request and response.