I am trying to call a web api service from C#. Following is the working fiddler trace.
POST https://clientsite.com/getAPI.json HTTP/1.1
Content-Type: text/plain
user: user
password: pass
key: Key
Host: clientsite.com
Content-Length: 63
Expect: 100-continue
Connection: Close
{"objectID":"XXXXX","objectType":"YYYYY"}
============================================ Now I wrote the following code... HttpWebRequest req =HttpWebRequest)WebRequest.Create(@"https://clientsite.com/getAPI.json");
req.Method = "POST";
req.ContentType = "text/plain";
string strNewValue = "login=user&password=pass&key=Key&objectID=XXXXXX&objectType=YYYYY";
byte[] byteArray = Encoding.UTF8.GetBytes(strNewValue);
req.ContentLength = byteArray.Length;
Stream dataStream = req.GetRequestStream();
dataStream.Write(byteArray, 0, byteArray.Length);
dataStream.Close();
HttpWebResponse response = (HttpWebResponse)req.GetResponse();
I am getting an authentication error. Obviously it didn't like the way I composed the request. Could any one help make an exact request like the fiddler trace please? Help is greatly appreciated.