Using web service, I was trying to upload image to web server. At present I want to upload profile picture to custom server but in this always, I was getting this error in Unity editor.
For this, I was using following code:
void Start ()
{
StartCoroutine (UploadPNG ());
}
IEnumerator UploadPNG ()
{
// We should only read the screen after all rendering is complete
yield return new WaitForEndOfFrame ();
// Create a texture the size of the screen, RGB24 format
int width = Screen.width;
int height = Screen.height;
var tex = new Texture2D (width, height, TextureFormat.RGB24, false);
// Read screen contents into the texture
tex.ReadPixels (new Rect (0, 0, width, height), 0, 0);
tex.Apply ();
// Encode texture into PNG
byte[] bytes = tex.EncodeToPNG ();
Destroy (tex);
// Create a Web Form
WWWForm form = new WWWForm ();
form.AddBinaryData ("profile_pic", bytes, "screenShot.png", "image/png");
// Upload to a cgi script
WWW w = new WWW (screenShotURL, form);
yield return w;
if (!string.IsNullOrEmpty (w.error)) {
print (w.error);
} else {
print ("Finished Uploading Screenshot");
}
}
This is similar code that I found from here: WWWForm
Hit another random page on that domain, you get a proper 404 response & page.
Now this is probably because I am trying to GET a URL which expects a POST along with other data, such as probably a hidden form field with a method name the web server expects. Responding with a 404 in this situation seems like poor HTTP to me as it looks like there is a resource there, it just doesn’t like your request, or the web server is configured to serve different 404 responses from /restapi than the rest of the domain, which is weird. IMO it should respond with a 400 Bad Request, or 403 Forbidden, depending.
Short version, it looks to me like you are missing some data to fulfil the request & this isn’t a Unity question. I’d look for a method parameter, check cookies, do you need to be signed in? etc etc. And read their restapi documentation. Either way, only the owner of that service can really help you I think…
Now I have answer for this question so that I am writing here. By considering that it may be useful to others.
Basically this problem is from server side. If I become specific towards problem then its IP address blockage problem.
I transferred my web server source code from one server to other. Then after same above code worked perfectly and image gets uploaded without any problem.
So please before wasting any time, check your server side first because this kind of error definitely belong to server as per my understanding.
the php source code image seems doesn’t longer exists, so if you don’t mind, could you reupload the image or share your php code, i really need it @siddharth3322