I am creating the web build which will run on the unity web player . I am getting the error which states that HTTP/1.1 500 Internal Server Error while calling the web service hosted on our data server… But when i called the web service hosted on my IIS Server , it works fine. and the web player run the game as well on the browser. I am stuck with this problem . Can someone help me to solve this problem. I am just exhausted by this error. Thanks in advance.
500 errors are most typically server misconfiguration errors of some kind. Unfortunately, they are a massive b**ch to track down as there’s no definitive starting point. Some common causes for 500 errors are:
Capitalization of URLs (only affects Apache/Unix servers). Apache sees “some-Name.html” and “some-name.html” as different pages. If your data server is Apache and the scripts run fine on your IIS server, there’s a good chance this is your problem.
Htaccess errors - if your htaccess file has a mistake in it that causes the server to loop endlessly, then you’ll get a 500. Likewise, if the htaccess is very complex, you might reach a point where the server is not sure which page it’s supposed to show, and returns a 500.
Database timeouts - if your data retrieval from a SQL DB is complex and large, the connection can go to sleep (shut down silently), but on some configurations this causes the server to get confused while running your scripts because it thinks the DB is just busy. If the 500 error comes back quickly, this is not your problem - this error usually comes up after the default DB timeout of 30 seconds.
Bad headers - depending on what you are returning from your scripts, if the headers are malformed or in some cases completely missing (rare) then you might get a 500 error as a default error instead of anything more useful. This is quite a rare occurrence, and chances are if you know enough web dev to be modifying headers to this degree, then you’ve probably already checked this.
As you say it runs fine on one server but not another, I’d start going through the configurations of both servers to ensure there are no obvious differences. It will most likely be something simple, but not necessarily obvious.
If this is a .Net webservice, then it’s usually because of a bug in the webservice - unable to find and/or deserialize the objects (not passed correctly, XML is wrong, etc). You should put a breakpoint in the webservice where it is being called, and step into it to see what is happening.
If it’s not a .Net webservice, then I have nothing for you.
This thread is old, but I would like to answer. Unity added UnityWebRequest to deal with webservices, webpages and APIs.
Use UnityWebRequest and set its UploadHandler to UploadHandlerRaw
As you have not given any code I would add my sample code
UnityWebRequest req = UnityWebRequest.Post("http://localhost:58755/User/AddNewUser", "POST");
req.SetRequestHeader("Content-Type", "application/json");
req.uploadHandler = new UploadHandlerRaw(Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(user))) as UploadHandler;
req.certificateHandler = new BypassCertificate();
yield return req.SendWebRequest();
if (req.isNetworkError || req.isHttpError || req.isError)
print("Error: " + req.error);
print(req.downloadHandler.text);
In case someone want to know about BypassCertificate. It is used to bypass certificate validation. I was using ASP.NET Core Webservice. it was causing problems. Hence, this bypasses certificate validation. Place this class anywhere in your code out of your current class.
public class BypassCertificate : CertificateHandler
{
protected override bool ValidateCertificate(byte[] certificateData)
{
return true;
}
}
In which case, we have to use UploadHandlerRaw?
Because I don’t have “user” variable to pass, I have 3 of int variables to pass as web request and receive response based on this web service call.
Occasionally I was getting this error, sometimes coming and sometime working properly so it become difficult for me to figure out.
Any suggestion will be welcome
You will want to test your web service via curl directly from a command line to ensure that your web service is working properly, start with the basics. You can also use a tool like PostMan. Then use a tool like Fiddler or Charles Proxy to compare the request coming out of your Unity app to the working request from curl/PostMan https://support.unity.com/hc/en-us/articles/115002917683-Using-Charles-Proxy-with-Unity
Is it your server?
The error 500 means an error happened on server side (commonly an exception was thrown and not handled). Such failures are typically a combination of problems with both your request and server-side code, hence having access to the server helps, you can investigate what blew up there.
Fix is also on both ends: a well written server should never give 5xx error, it should give 4xx response, preferably detailing what it didn’t like in request.
@JeffDUnity3D and @Aurimas-Cernius Thank you to both of you for your suggestions
Now let me reply for your questions and share more details from my side.
From last few days I don’t have this issue but today again started coming:
This is the error that started showing again and with my surprise, I was getting this error within the same web service through my project includes multiple web services and communication with the web server.
But only this web service showing 500 internal web server error.
If I am executing web service on PostMan then its working properly, I didn’t notice this problem in PostMan.
Only Unity editor giving this error.
Currently I am using Unity 2021.1.13f1 for my project.
This is our custom web server that we were using to hold all server things and communicating through different web services.
After reading this details, please share your thoughts for this problem.