Reputation: 1329
When making a call to my webapi running locally, I am passing data in the requestUri as base64 encoded Json of my serialized object, but getting StatusCode 400 at every turn.
How do I fix my request?
public class VerifyController : ApiController
{
// GET: api/Verify/jsonStringAddressOriginal
public AddressResult Get(string base64AddressOriginal)
The caller:
var requestUri = string.Format("api/verify/{0}", base64address);
Console.WriteLine("requestUri:\n{0}", requestUri);
HttpResponseMessage response = client.GetAsync(requestUri).Result;
requestUri:
api/verify/eyJDb21wYW55IjoiIiwiQWRkcmVzcyI6Ijc3NTAgQmVsZm9ydCBQYXJrd2F5IDIwMCIsI
kFkZHJlc3MyIjoiIiwiU3VpdGUiOiIiLCJDaXR5IjoiSmFja3NvbnZpbGxlIiwiU3RhdGUiOiJGTCIsI
lppcCI6IjMyMjU2IiwiUGx1czQiOiIiLCJMYXN0TGluZSI6IiIsIkNvdW50cnlDb2RlIjoiIiwiVXJiY
W5pemF0aW9uIjoiIiwiTGFzdE5hbWUiOiIiLCJQYXJzZWRBZGRyZXNzUmFuZ2UiOiIiLCJQYXJzZWRQc
mVEaXJlY3Rpb24iOiIiLCJQYXJzZWRTdHJlZXROYW1lIjoiIiwiUGFyc2VkU3VmZml4IjoiIiwiUGFyc
2VkUG9zdERpcmVjdGlvbiI6IiIsIlBhcnNlZFN1aXRlTmFtZSI6IiIsIlBhcnNlZFN1aXRlUmFuZ2UiO
iIiLCJQYXJzZWRSb3V0ZVNlcnZpY2UiOiIiLCJQYXJzZWRMb2NrQm94IjoiIiwiUGFyc2VkRGVsaXZlc
nlJbnN0YWxsYXRpb24iOiIifQ==
Error code: BadRequest
Reason: Bad Request
I think it's a malformed request but I don't know in what way. There seem to be no further properties of the response object detailing which error that the 400 Status Code represents. http://msdn.microsoft.com/en-us/library/azure/dd179357.aspx
This is my first WebApi so when answering, make no assumptions about my configuration. VS2013 update 3, Web Api, using an HttpClient as the caller.
Upvotes: 1
Views: 1632
Reputation: 2621
I didn't count the number of characters in your URI, but very long URIs (> 2000 characters) are likely to cause problems. Try making this a POST request and putting the base64 data into the request body.
Upvotes: 1