Escape double quote in WCF rest - wcf

We host a WCF RESTful service. There is one service that is of verb POST, and it is possible to pass in double quotes as part of the message. This is causing issues. I tried the standard back slash to escape it, but that didn't work. Any suggestions? Here is the request body:
{"GardenWidth":"16' 7"","GardenLength":"62", "GardenStyle":"General","PostalCode":"12345",}

Try removing the comma after "12345":
{
"GardenWidth": "16' 7\"",
"GardenLength": "62",
"GardenStyle": "General",
"PostalCode": "12345"
}

Related

postman giving 400 bad request when i use global varibales how to solve this

when i use normal json body postman gives me 201 created response but when i am using global variable postman giving me 400 bad request
Variables still need to be used in proper JSON format therefore you should be putting your strings in quotes:
{
"email": "{{email}}",
"password" : "{{password}}",
"confirmpassword" : "{{confirmpassword}}"
}
See https://learning.postman.com/docs/sending-requests/variables/
Side note: please provide actual "happy path" (when it worked) as well as your errors. Text instead of images is good too to help people try to reproduce your errors without a lot of typing

Getting illegal character when sending GET request in JMETER. Working fine in browser

Im getting illegal character in JMETER for GET request -
https://dev1/api/v1/query/job/?filter={%22job_manager_id%22:%22553f2350-12d3-4252-8fe0-39691019c495%22}
tried replacing %22 with "" but still getting illegal character.
Any solutions ?
I think problematic characters are { and }, they need to be percent-encoded
The options are in:
Tick "URL-encode" box next to the filter parameter in the HTTP Request sampler :
Use __urlencode() function in "Path" field like
see Apache JMeter Functions - An Introduction article to learn more about JMeter Functions concept
Or just hard-code the percent-encoded Path part like:
https://dev1/api/v1/query/job/?filter=%7B%22job_manager_id%22%3A%22553f2350-12d3-4252-8fe0-39691019c495%22%7D

Asterisk (*) not allowed in Status Update

I'm trying to use the Twitter v1.1 API endpoint:
POST : https://api.twitter.com/1.1/statuses/update.json?status=%2A
-or-
POST : https://api.twitter.com/1.1/statuses/update.json?status=*
After seeing some suggestions about URL Encoding (percent encoding) I'm trying to encode the asterisk (*) character using %2A
Other character encoding works, as expected. But the asterisk character results in the following error:
{ "errors": [{ "code": 32, "message": "Could not authenticate you." }]}
You can reproduce the error using the API Console Tool:
https://dev.twitter.com/rest/tools/console2
For Authentication I chose the Oauth 1 option.
It is possible to send a single * as a status update via the API - see https://twitter.com/edent/status/664713007268823040
I suspect that the library you're using isn't properly calculating the OAuth signature. It would help if you showed us the code you use and which library you're relying on.
Just replace the asterisk * with the wide-asterisk *. It is perfectly working for me
String tweet_text="Tweet text with asterisk *";
tweet_text= tweet_text.replaceAll("[*]","*");

How to properly encode special characters in a REST API url

EDIT: The NHTSA docs, as CBroe points out, say to replace an ampersand with an underscore. However, I'm also getting an error with forward slashes (albeit a different one, page not found, because it's decoding the slash), for example the make 'EXISS/SOONER':
http://www.nhtsa.gov/webapi/api/Recalls/vehicle/modelyear/1997/make/EXISS%2FSOONER?format=json
And replacing the ampersand with an underscore no longer results in an error message, but in zero results returned, which should not be the case.
ORIGINAL POST:
I'm trying to download the content from the following URL:
http://www.nhtsa.gov/webapi/api/Recalls/vehicle/modelyear/1997/make/s&s?format=json
And the site returns the following error message:
Server Error in '/' Application.
A potentially dangerous Request.Path value was detected from the client (&).
The problem is the ampersand; a similar request for a different car make works:
http://www.nhtsa.gov/webapi/api/Recalls/vehicle/modelyear/1997/make/toyota?format=json
I have verified from a different endpoint that S&S is a valid make for the API.
Based on stackoverflow answers, I've tried all the following without success:
http://www.nhtsa.gov/webapi/api/Recalls/vehicle/modelyear/1997/make/s%26s?format=json
http://www.nhtsa.gov/webapi/api/Recalls/vehicle/modelyear/1997/make/s%26amp;s?format=json
http://www.nhtsa.gov/webapi/api/Recalls/vehicle/modelyear/1997/make/s%26amp%3Bs?format=json

' character in string parameter of Odata Url

Hmmm this seems silly, so I feel silly. I have a custom operation on an Odata service which has a string parameter. It works fine when the string contains no special characters, but as soon as I include the ['] character I get:
<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\"?>\r\n<error xmlns=\"http://schemas.microsoft.com/ado/2007/08/dataservices/metadata\">\r\n <code></code>\r\n <message xml:lang=\"en-US\">Bad Request - Error in query syntax.</message>\r\n</error>
I am invoking the service with the following code:
new DataServiceContext(new Uri(svcUri)).Execute<string>(new Uri(relativeOperationUrl, UriKind.Relative));
I've tried encoding like this [& apos;] (xml encoding) and like this [%27] (url encoding) and the things is still blowing up.
Try '' (like escaping it for SQL); see How to escape a single quote to be used in an OData query?.