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

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"

Related

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

Include | in url without url encoding it using NSURLConnection

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.

Cannot parse feed

I'm trying to parse this feed http://www.bbc.co.uk/sport/football/teams/newcastle-united/rss.xml
I get this message "A feed could not be found at http://. A feed with an invalid mime type may fall victim to this error, or SimplePie was unable to auto-discover it.. Use force_feed() if you are certain this URL is a real feed."
If I use force_feed I get an error "This XML document is invalid, likely due to invalid characters. XML error: Mismatched tag at line 27, column 8" but looking at the xml I can't see any errors. Indeed, checking at http://validator.w3.org/ seems to validate fine.
Any suggestions?
I'm running the latest version of simplepie downloaded a few days ago.
I found the problem when I stripped out the code to create a test case. The url being loaded was http://www.bbc.co.uk//sport/football/teams/newcastle-united/rss.xml (notice the double forward slash). simplepie seems to not be dealing with this gracefully. Removing the double slash fixes the problem

SharePoint 2010 REST in iOS returns bad URL

I'm trying to query a Sharepoint List using REST. It works in IE and Chrome but in iOS after sending async request it jumps directly to didFailWithError returning:
Error Domain=NSURLErrorDomain Code=-1000 "bad URL" UserInfo=0xe95ba00 {NSUnderlyingError=0x8258680 "bad URL", NSLocalizedDescription=bad URL}
The REST code is:
#"http://mySP/site/siteColl/_vti_bin/ListData.svc/MyList?$filter=Infotyp eq 'NO'"
If I use:
#"http://mySP/site/siteColl/_vti_bin/ListData.svc/MyList"
instead, then everything is fine. Authorization is not an issue.
So why is the filter not working?
EDIT: Found out why. It's the spaces in the query. But how should I format them?
Got it. Used RESTQuery = [RESTQuery stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding] which returns a legal URL encoding

Trying to send text message using sp_send_dbmail truncates url in body

I'm using send_dbmail to send a text message to customers. This is the following sql:
exec msdb.dbo.sp_send_dbmail
#recipients='5558881234#txt.att.net',
#body='check out this url https://www.someurl.com/directory/blah.aspx',
#subject='I am the subject!'
The body gets truncated to "check out this url https://www.someurl.com/directory/blah.as" (the "px" is removed from the end of the url).
I've ruled out message length as I have tried sending just "www.google.com/test.aspx" and the "px" is removed as well. Another strange thing, when I try forwarding the text message to myself and add the "px" back on myself, it works. It also works if I send a email from outlook with the same body.
Any ideas?
Thanks.
Seems strange. Have you tried passing unicode strings, i.e. N'check out this url ....', or silly suggestion, have you tried padding the end of your string with a few whitespace characters, or perhaps a few whitespace characters followed by a period? What happens if the body text doesn't end in .aspx, but ends in anything else such as "this is a test", etc.?