#POST
#Consumes("application/x-www-form-urlencoded")
#Produces("application/json")
Response doSearch( MultivaluedMap<String, String> formParams,
#Context UriInfo uriInfo);
I'm using JAX-RS and the above code always throws a 415 - Unsupported Media Type Error. Even though when I look at the header in the POST via firebug the content type is listed as "application/x-www-form-urlencoded; charset=UTF-8". The form is being sent using dojos xhrpost.
I looked all over the place and cannot figure out why this isn't working. If I switch from using the MultiValuedMap to specifically stating all the #FormParams it works fine, but in my case I need to use the Map because I'm unsure of the number of parameters that the form will send.
Anyone have any ideas? Thanks in advance. If you need any further information please let me know.
Related
.NET 6, purely WebAPI project. I have an endpoint method that is expecting a urlencoded form in the POST data. The method is added to the routing table by app.MapPost("/myendpoint", MyClass.MyEndpoint) in the program's startup file; it's not in a controller. The method currently goes:
[Consumes("application/x-www-form-urlencoded")]
[HttpPost]
public static async Task<IResult> MyEndpoint([FromForm]FormData TheForm)
where FormData is a record with the expected form fields.
I've tried some other annotations. The framework just won't let me consume the form. When invoked, the method either returns HTTP error 415, or, in some iterations, an exception is thrown somewhere in the pipeline saying that "Expected a supported JSON media type but got "application/x-www-form-urlencoded"."
Is urlencoded form parameter binding even supported in WebAPI? I would even settle for the form contents as a string, won't mind parsing myself (HttpUtility.ParseQueryString to the rescue).
For the time being, I read Request.Body from the HTTP context' request body, but that's crude and also error prone, as the context is known to go poof sometimes in async methods.
EDIT: also tried placing .Accepts<FormData>("application/x-www-form-urlencoded") on the MapPost() line. Same result.
Tried replacing the body parameter with [FromBody]byte [] Body, [FromBody]string Body.
Postwoman (now Hoppscotch) is an API request builder (like Postman) that I love the idea of because it's open source, but I'm not getting any response showing up in the Response field. It's a private API I'm hitting so I'd rather not show my request but it's a POST and my API is sending back the correct response (that works fine in Postman). I'm seeing the following error in the browser console:
TypeError: text.match is not a function
Is anybody else having this problem?
Adding browser extension:
https://addons.mozilla.org/en-US/firefox/addon/hoppscotch/
done the trick for me
I am trying to void the "In-Process" DocuSign envelope through REST API call. I am using changeStatus method to void the envelope. We are setting the status as "voided" and reason as "voidedReason" in StatusChangeRequest object.
However, after REST API call envelope doesn't get voided. Status remains as "In Progress" in Web-Console.
Any help to resolve this issue?
Thanks,
Shriniwas
I just voided several of my envelopes and had no problems, you must be doing something wrong. What's the return code when you make the request, are you receiving a 200 or something else? I suspect one of 4 common problems with your request:
You are setting the request body wrong.
You are doing a POST request instead of a PUT request.
You are PUT-ing to the wrong URI.
You are trying to void the wrong envelope.
The body for the void request is very simple so let's start with that. I just voided all of my envelopes with the following request body:
{
"status": "voided",
"voidedReason": "Void Testing..."
}
Next make sure you are doing a PUT request and not a POST, as is a common mistake, and also make sure you are PUT-ing to the correct URI (following is for DEMO environment):
https://demo.docusign.net/restapi/v2/accounts/{accountId}/envelopes/{envelopeId}
Of course, make sure you are using a valid envelopeId that is currently in status "In-Process" and that you check the correct corresponding envelope after the call. For more information on the void call see THIS LINK.
I have a really weird situation (may be its for me only). I developed a RESTful API. By default it returns the result as JSON/XML/TEXT as per the Content Type sent by the client in headers.
Now client is saying that he wants to set the response as default as XML only. What I mean here is that client will not send any content type in headers and it will by default send the request as XML.
When I access this API from browser, it return it as XML but when client's app requests it, it returns JSON result by default. They are getting the result as XML by putting the content type in headers but they don't want to do it and want to have XML result by default.
I hope I am clear on it. If not please let me know.
Any help would be appreciated. Thanks
[Change]
I am interested in knowing if there is some way I can modify the request headers when I receive request on server.
It is in MVC3, C#.
You can't change the request headers, just query them.
I guess you return your result as a simple string in your controllers, isn't it?
And, you are switching between results depending on the contenttype you read from request, don't you?
What is the contenttype the client call come with?
UPDATE:
Look at this page:
http://aleembawany.com/2009/03/27/aspnet-mvc-create-easy-rest-api-with-json-and-xml/
It's a solution for a previous version of MVC, but it will give you an idea about the solution you need:
Adjust the action result depending on the request contenttype
I find the answer and posting here. I just removed the other return types except the xml type like below:
void ConfigureApi(HttpConfiguration config)
{
// Remove the JSON formatter
config.Formatters.Remove(config.Formatters.JsonFormatter);
// or
// Remove the XML formatter
config.Formatters.Remove(config.Formatters.XmlFormatter);
}
For more details, please follow below link
http://www.asp.net/web-api/overview/formats-and-model-binding/json-and-xml-serialization
Thanks
I'm trying to get my access token for my application, using this URL:
https://datamarket.accesscontrol.windows.net/v2/OAuth2-13?grant_type=client_credentials&client_id=//CLIENT ID//&client_secret=//CLIENT SECRET//=&scope=http://api.microsofttranslator.com
Obviously I replace //CLIENT ID// and //CLIENT SECRET// with my applications information.
I tried encoding the tokens with HtmlEncode in my application but got a 400 error. So I tried the request in my browser and this is the JSON response I got:
{
"error":"invalid_request",
"error_description":"ACS90007: Request method not allowed. \r\nTrace ID: 2144c829-f3fa-4ed8-80e6-40841e6a3f69\r\nTimestamp: 2012-06-27 01:11:27Z"
}
I don't know what I'm doing wrong, any help?
I believe when you are making the WebRequest call your parameter is set to use GET and this will cause error ACS90007. When making the WebRequest call please use POST along with application/x-www-form-urlencoded set Content-Type.
If you still have problem post your WebRquest code snippet and i will take a look.
It would be better if you can provide the code for AdmAuthentication. For now, please make sure you have correctly translated the code on http://msdn.microsoft.com/en-us/library/hh454950 to VB. Please also try to use Fiddler to monitor the request to ensure it is sending a POST request.
Best Regards,
Ming Xu.
Making my own client secret helped my cause