I am in a situation where I know I can connect to an endpoint (using Postman chrome app) but I get an authentication error when I attempt it through HttpClient executing as WebJob on Azure.
public string ScanEndPoint()
{
string result;
using (var client = new HttpClient())
{
var requestContent = new MultipartFormDataContent();
var url = $"{Host}/{Path}";
requestContent.Add(new StringContent("*"), Version);
requestContent.Add(new StringContent("***"), Reference);
requestContent.Add(new StringContent("********"), Password);
var response = client.PostAsync(url, requestContent).Result;
result = response.Content.ReadAsStringAsync().Result;
}
return result;
}
The MultipartFormData is because I have to post the credentials in the body and not as headers. Clicking on the code link in Postman shows:
POST /*************.php HTTP/1.1
Host: *****-*******.****.******
Cache-Control: no-cache
Postman-Token: b574e803-1873-d7dd-ff10-bfc509991342
Content-Type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW
------WebKitFormBoundary7MA4YWxkTrZu0gW
Content-Disposition: form-data; name="*"
**
------WebKitFormBoundary7MA4YWxkTrZu0gW
Content-Disposition: form-data; name="***"
****
------WebKitFormBoundary7MA4YWxkTrZu0gW
Content-Disposition: form-data; name="*********"
********************************
------WebKitFormBoundary7MA4YWxkTrZu0gW--
What steps do I need to take to replicate that postman request so that it works in code?