Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have created the experiment in Microsoft Azure ML and deployed as Web service and it creates the URL & API key.

But I need to pass the inputs (Country, SSN) from Visual Studio 2015 ASP.NET to get the output from Azure ML experiment which I have created

So I have created the web form in Visual Studio 2015 ASP .Net with inputs are 'Country' and 'SSN' and sending the request from ASP .NET using the created URL, API key and inputs to get the response from Azure ML.

--Sending the request from ASP .NET to Azure ML
C#
'HttpResponseMessage response = await client.PostAsJsonAsync("", scoreRequest).ConfigureAwait(false);'


But I am facing the below error when getting the response from Azure ML.

{StatusCode: 400, ReasonPhrase: 'Bad Request', Version: 1.1, Content: System.Net.Http.StreamContent,
Headers:{ x-ms-request-id: cf719cd0-a627-4b69-8b11-77a7e85ee7a3 Date: Thu, 24 Sep 2015 18:57:50 GMT Server: Microsoft-HTTPAPI/2.0 Content-Length: 194 Content-Type: application/json; charset=utf-8}}

Please find the Sample Code below:

C#
using (var client = new HttpClient())
                {
                    var scoreRequest = new
                    {
                        Inputs = new Dictionary<string,>() {
                       {
                            "input1",
                            new StringTable()
                            {
                                  ColumnNames = new string[] {"Country", "SSN"},
                                  Values = new string[,] { { strCountry, SSN} }
                            }
                        },
                     },
                        GlobalParameters = new Dictionary<string,>()
                        {
                        }
                    };

                    const string apiKey = "4mgUBPxzQIuFPjR7ACHwm3epGRtlznVF9svU0zbshMTQl9l6M2/MpT+FKhOmytkj8Dhv9QuwWHxIJOis9QsvHg=="; 
                    client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", apiKey);

                    client.BaseAddress = new Uri("https://ussouthcentral.services.azureml.net/workspaces/cba5f97476104d3697ad920b1e7a136d/services/2694f6eafd7f4a74937eb9ddb85bcc90/score");

                    HttpResponseMessage response = await client.PostAsJsonAsync("", scoreRequest).ConfigureAwait(false);

                    if (response.IsSuccessStatusCode)
                    {
                        string result = await response.Content.ReadAsStringAsync();
                        Console.WriteLine("Result: {0}", result);
                    }
                    else
                    {
                        Console.WriteLine(string.Format("The request failed with status code: {0}", response.StatusCode));

                        // Print the headers - they include the requert ID and the timestamp, which are useful for debugging the failure
                        Console.WriteLine(response.Headers.ToString());

                        string responseContent = await response.Content.ReadAsStringAsync();
                        Console.WriteLine(responseContent);
                    }
                }
            }



Please help me to provide the solution to fix this issue.
Posted
Updated 5-Jul-17 7:39am
v2

1 solution

You are sending a JSON string which does not conform to the specification of the service you are calling. That is why you are getting a BAD request. I had the same issue and I discovered that one property was in uppercase instead of lowercase.
 
Share this answer
 
Comments
evry1falls 15-May-20 18:56pm    
I know it's been long since this. But how did you solve the Capitalization issue.
I'm having the same problem with the same error from the above Q.

{StatusCode: 400, ReasonPhrase: 'Bad Request', Version: 1.1, Content: System.Net.Http.StreamContent, Headers:
{
X-GUploader-UploadID: AAANsUmjFKaluoP62kb0Jdg90SQQ6SB61Fwz9J93JhzJSIlBwXnkD5eDzj35mNtbTlP1U4S64DKZOBjFqmOp9JPNUHWjQjgnbA
Vary: Origin
Vary: X-Origin
Alt-Svc: h3-27=":443"; ma=2592000,h3-25=":443"; ma=2592000,h3-T050=":443"; ma=2592000,h3-Q050=":443"; ma=2592000,h3-Q049=":443"; ma=2592000,h3-Q048=":443"; ma=2592000,h3-Q046=":443"; ma=2592000,h3-Q043=":443"; ma=2592000,quic=":443"; ma=2592000; v="46,43"
Date: Fri, 15 May 2020 22:51:51 GMT
Server: UploadServer
Content-Length: 259
Content-Type: application/json; charset=UTF-8
}}

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900