Gani tpt
asked on
How do we receive list of documents from Web service using Web API..?
How do we receive list of docs number while calling Web API client.
I am getting error : "Status Code: 406, ReasonPhrase:Not Acceptable',....
But, the service is correct and all other remaining values are correct. but, finally we are getting the error.
Scrrenshot attached for reference (Status Code).
Source is below:
------------------------
What is the problem in the above code..? How do we receive the list of doc numbers..?
StatusCode.png
I am getting error : "Status Code: 406, ReasonPhrase:Not Acceptable',....
But, the service is correct and all other remaining values are correct. but, finally we are getting the error.
Scrrenshot attached for reference (Status Code).
Source is below:
------------------------
private const string URL = "http://testURL.net/getDocs";
private const string DATA = @"{""EmpId"": ""101"",""EmpName"": ""ANDREWS"",""Dept"": ""Accounts""}";
System.Net.Http.HttpClient client = new System.Net.Http.HttpClient();
client.BaseAddress = new System.Uri(URL);
byte[] cred = UTF8Encoding.UTF8.GetBytes("username:password");
client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Basic", Convert.ToBase64String(cred));
client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/x-www-form-urlencoded"));
System.Net.Http.HttpContent content = new StringContent(DATA, UTF8Encoding.UTF8, "application/x-www-form-urlencoded");
HttpResponseMessage messge = client.PostAsync(URL, content).Result;
string description = string.Empty;
if (messge.IsSuccessStatusCode)
{
string result = messge.Content.ReadAsStringAsync().Result;
description = result;
}
What is the problem in the above code..? How do we receive the list of doc numbers..?
StatusCode.png
What is the service API need for input? and what does it return? check the service documentation
ASKER
Input : {""EmpId"": ""101"",""EmpName"": ""ANDREWS"",""Dept"": ""Accounts""}
Method : post
Receiving output (List<string>) : { "ACToo1","IMN201","RAK101" ,....}... ====> Doc numbers as output...
we tried to execute in third party tool. (SoapUI 5.4.0).. it is working fine.. below is the output..
HTTP/1.1 200 OK
Server: Apache-Coyote/1.1
Access-Control-Allow-Origi n: *
Access-Control-Allow-Metho ds: POST, GET, OPTIONS, DELETE
Access-Control-Max-Age: 3600
Access-Control-Allow-Heade rs: Access-Control-Allow-Heade rs, Origin,Accept, X-Requested-With, Authorization, Content-Type, Access-Control-Request-Met hod, Access-Control-Request-Hea ders, x-csrf-token
Content-Type: application/json
Transfer-Encoding: chunked
Date: Wed, 28 Nov 2018 07:40:44 GMT
["ACToo1","IMN201","RAK101 "]
But, we are not sure where we have to change in our code...?
Method : post
Receiving output (List<string>) : { "ACToo1","IMN201","RAK101"
we tried to execute in third party tool. (SoapUI 5.4.0).. it is working fine.. below is the output..
HTTP/1.1 200 OK
Server: Apache-Coyote/1.1
Access-Control-Allow-Origi
Access-Control-Allow-Metho
Access-Control-Max-Age: 3600
Access-Control-Allow-Heade
Content-Type: application/json
Transfer-Encoding: chunked
Date: Wed, 28 Nov 2018 07:40:44 GMT
["ACToo1","IMN201","RAK101
But, we are not sure where we have to change in our code...?
Isn't your request payload JSON data? But in the headers you have marked it as "application/x-www-form-ur lencoded"
Try using "application/json" content type.
Try using "application/json" content type.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thnaks to all for great suggestions..
ASKER