- Home /
[ASP.NET] [WEB API] Problem with HttpWebRequest.ContentType
Hey guys,
I'm trying to send an image taken from my webcam to a web API for processing. So I take a screenshot and store it in a Texture2D variable, then convert that to a byte[] by calling EncodeToPNG().
What kind of ContentType should I set for this? None of the ones I've tried seem to work.
This is my HttpWebRequest code:
myWebRequest = (HttpWebRequest)WebRequest.Create("http://localhost:64050/api/ZXing/BeginDecode");
myWebRequest.Method = "POST";
//Set ContentType here
myWebRequest.ContentLength = bytes.Length;
Stream dataStream = myWebRequest.GetRequestStream();
dataStream.Write(bytes, 0, bytes.Length);
dataStream.Close();
response = myWebRequest.GetResponse();
Stream data = response.GetResponseStream();
StreamReader reader = new StreamReader(data);
Debug.Log(reader.ReadToEnd());
Here's my camera code, just incase:
camSnapshot = new Texture2D(camTex.width, camTex.height, TextureFormat.RGB24, false);
camSnapshot.SetPixels(camTex.GetPixels());
camSnapshot.Apply();
bytes = camSnapshot.EncodeToPNG();
File.WriteAllBytes(Application.dataPath + "/../SavedScreen.png",bytes);
Making and working with Web APIs are new to me so sorry if it's a dumb problem.
Thanks.
Your answer
Follow this Question
Related Questions
UnityWebRequest returning responseCode 0 and isNetworkError == true for Unity 2019 1 Answer
Server-Side Events with UnityHTTPWebRequests (text/event-stream) 0 Answers
HTTP PUT in Unity for iOS? 2 Answers
get a mysterious problem,when i use HttpWebRequest in unity c# script. 1 Answer
UnityWebRequest object downloadhandler.text not returning same/all data compared to browser 0 Answers