Include | in url without url encoding it using NSURLConnection - objective-c

I am using an API that needs the | character in the URL. I tried changing that character to %7C, but the API rejects it. Now the issue is NSURLConnection gives me this if I include a | in the url:
NSURLErrorDomain Code=-1000 "bad URL" UserInfo=0x610000272bc0 {NSLocalizedDescription=bad URL, NSUnderlyingError=0x600000247b60 "bad URL"}
How can include the | in my URL?

You can't: the pipe character is a so called unsafe character and must always be percent escaped to form a valid URL. See RFC 1738 for the syntax of a valid URL.
You should contact the developers of the service you are using and ask them to change this peculiarity of their API's behavior.

Related

JMeter encode URL

I have to test the below URL that contains special char:
url\search.html?q=*&Filters=template_fac_s:3f87222389034212a868c5c0cd12cacc|market_l1_fac_sm:e73956c2506442399dd73ed1eb0ec165
I am getting this error:
Response message: Non HTTP response message: Illegal character in query at index 121: url/search.html?q=*&Filters=template_fac_s:3f87222389034212a868c5c0cd12cacc|market_l1_fac_sm:e73956c2506442399dd73ed1eb0ec165
I think I need to encode the URL but I do not know how to do it . Does anyone know how to do this , can someone help.
Thanks.
JMeter provides __urlencode function which replaces characters which are not allowed in URL with url-encoded equivalents
References:
Understanding HTML Form Encoding: URL Encoded and Multipart Forms
Apache JMeter Functions - An Introduction

sending € character to web server via VBA

I am using MSXML2.XMLHTTP60 to send text messages via VBA using a web server. I cannot understand why the € symbol is not displayed when receiving a text message. Other special characters, such as ò,à,è etc are displayed after a conversion function I wrote (for example à is encoded as "%E0"). I suppose that web server is expecting charset iso 8859-1 which doe not support € symbol. Therefore how can I solve this problem?
If your request is a POST request then you can specify header for Content-Type with encoding e.g. like this:
objHTTP.Open "POST", ...
objHTTP.setRequestHeader "Content-Type", "text/html; charset=utf-8"
But for GET request the URL with possible query string parameters will be encoded as ASCII. Read e.g. this post.
Using UTF-8 as your character encoding should solve such problems. It may also remove the need for your conversion function. I'm not sure how to set the encoding in your web server, but that's usually well documented.

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

NSURLErrorDomain Code=-1000 "bad URL": What does it really mean?

I have this confusing error. I am sending JSON through GET method and a website will parse and display the data. The problem is I am getting the error "NSURLErrorDomain Code -1000" or more simply "Bad URL". The thing is when I check the server, the data I sent is successfully parsed and displayed. So I am really confused why am I getting this "bad URL" error at all. Can anyone helped me out?
Here is the error I am receiving:
Error Domain=NSURLErrorDomain Code=-1000 "bad URL" UserInfo=0xff73df0 {NSUnderlyingError=0xff73810 "bad URL", NSLocalizedDescription=bad URL}
EDIT:
http://sample.com/imwebjson.php?sid=5amp13&job=sendNotes&im_flds={\"im_uid\":"1",\"im_bookid\":"57",\"im_pagenr\":"1",\"im_notes\":"Testing%5C%5Cn"}
Ok you might ask why some parts of the JSON string is encoded already. These encoded parts are special characters. I realized that the stringByAddingPercentEscapesUsingEncoding is very incomplete. It doesn't encode all special characters, and what more is that when it encodes some special characters, the URL is not recognized at all. So I decided to manually encode the special characters into the string.
The colon character : (at least, possibly others like " and {) needs to be percent encoded in URLs.
In the GET parameters you have to change spaces " " for "%20"