I am using AFNetworking to fetch data from the server.
When there is an accented character in my URL I get an error like this:
userInfo={"NSUnderlyingError"=>#<__NSCFError:0xfd3aa70,
description="bad URL", code=-1000, domain="kCFErrorDomainCFNetwork",
userInfo={"NSLocalizedDescription"=>"bad URL"}>,
"NSLocalizedDescription"=>"bad URL"}>
However, when I try the URL from a browser (chrome), my backend API returns the results fine.
Here is a sample URL I'm trying: http://localhost:9000/my/Jalapeños
A URL requires to be properly encoded. Given your example is a string representing a URI, it's definitely wrong.
You may take a look at NSURLComponents (available for OSX >= 10.9 and iOS >= 7.0) and RFC 3986.
Related
I am trying to consume the google text to speech api here : https://cloud.google.com/speech-to-text/docs/async-recognize#speech-async-recognize-gcs-protocol
and it has this url format below
https://google-speech-api-base-urlspeech:longrunningrecognize
What is this URL format with colon(:)in the end?
When I try to hit this URL, it gives me an error specifically while running test case on it .e. Invalid URI. Invalid Port?
But the official google documentation says this is a valid url? How to use this?
This format of URL is called gRPC Transcoding syntax. Your first URL is invlaid , because it's in the first path segment of a relative-path reference.
https://google-speech-api-base-urlspeech:longrunningrecognize
This url is invalid for usage, whereas the one below, https://speech.googleapis.com/v1/speech:longrunningrecognize was running fine.
Try changing your URL to something like
https://google-speech-api-base-url/speech:longrunningrecognize. It will work.
I looked at the documentation page you referenced and was unable to see/find a URL that looked like:
https://google-speech-api-base-urlspeech:longrunningrecognize
However, what I did find was a URL of the form:
https://speech.googleapis.com/v1/speech:longrunningrecognize
which looks perfectly valid.
The documentation for this REST request can be found here:
https://cloud.google.com/speech-to-text/docs/reference/rest/v1/speech/longrunningrecognize
Could you have made an error in your reading and comprehension?
Apparently the colon (:) is legal in the path part of a URL:
Are colons allowed in URLs?
I am using resumable file upload which works fine for files without Norwegian character in it. If the file name has Norwegian character in it the uploadSession is established and after that when I sent the content on the uploadUrl returned from upload session request the call fails and gives the following error.
{
"error":"invalid_request",
"error_description":"This access token is not valid on this endpoint."
}
However from the same file if I remove this character (ø) everything works fine.
This the sample url returned from the createUploadSession endpoint.
https://<sharepoint_sitename>/sites/jnu/_api/v2.0/drives/b!uey_5Lpf8Eu0-5HlGvJvFga89s_hTxNAg9kSsTlOBqajRqOF3ec-Rp6uqtbLNt4w/items/016GMDDVAF3UIOU2YNWVE3TX24ZV44WN4K/uploadSession?guid=%274ce82b5c-ede4-4d1d-af0a-6ff3b33c10b7%27&path=%27%7etmp41_Decisions+-+Advania+sdfsldfasduftest%u00f8+a%27&overwrite=True&rename=False&tempauth=eyJ0eXAiOiJKV1QiLCJhbGciOiJub25lIn0.eyJhdWQiOiIwMDAwMDAwMy0wMDAwLTBmZjEtY2UwMC0wMDAwMDAwMDAwMDAvZmlnZy5zaGFyZXBvaW50LmNvbUBjNzEwNWRkYS1hNTQ4LTRkZWYtOGVlNy1lOTkyZTBlNmRjYjAiLCJpc3MiOiIwMDAwMDAwMy0wMDAwLTBmZjEtY2UwMC0wMDAwMDAwMDAwMDAiLCJuYmYiOiIxNTAyMDk4NDM0IiwiZXhwIjoiMTUwMjE4NDgzNCIsImVuZHBvaW50dXJsIjoiQ1A3T2Q0OVBKR25Scy9TbnN0akNUbk5BV29KeEJhdzFVNnNCTHY5SG5oND0iLCJlbmRwb2ludHVybExlbmd0aCI6IjMwMiIsImlzbG9vcGJhY2siOiJUcnVlIiwiY2lkIjoiWW1JMk1tUTFaamd0TkRZMllpMDBaR1JtTFdJM1lqY3ROVE5qWTJNMU1UZ3lNbU5qIiwidmVyIjoiaGFzaGVkcHJvb2Z0b2tlbiIsInNpdGVpZCI6IlpUUmlabVZqWWprdE5XWmlZUzAwWW1Zd0xXSTBabUl0T1RGbE5URmhaakkyWmpFMiIsIm5hbWVpZCI6IjAjLmZ8bWVtYmVyc2hpcHxkZWVwYWsuc2hhcm1hQGRlY2lzaW9ucy5ubyIsIm5paSI6Im1pY3Jvc29mdC5zaGFyZXBvaW50IiwiaXN1c2VyIjoidHJ1ZSIsImNhY2hla2V5IjoiMGguZnxtZW1iZXJzaGlwfDEwMDM3ZmZlOTY2MjcxYmNAbGl2ZS5jb20iLCJ0dCI6IjAiLCJ1c2VQZXJzaXN0ZW50Q29va2llIjpudWxsfQ.MTl0bEZ6cldwUlZEVUkwcEphUkpnWDRVelNnWnFWQndlVEtpbG9ndlhLYz0
This was a regression introduced when the session URLs were updated to a new format - it should now be fixed!
How to prevent a server from returning an error 400 code error when the URL contains % symbol using NGINX server?
Nginx configuration for my website:
....
rewrite ^/download/(.+)$ /download.php?id=$1 last;
....
When I tried to get access to this URL:
http://mywebsite.net/download/some-string-100%-for-example
I got this error:
400 Bad Request
With this url :
http://mywebsite.net/download/some-string-%25-for-example
it's work fine !
It's because it needs to be URL encoded first.
This will explain:
http://www.w3schools.com/tags/ref_urlencode.asp
URLs can only be sent over the Internet using the ASCII character-set.
Since URLs often contain characters outside the ASCII set, the URL has to be converted into a valid ASCII format.
URL encoding replaces unsafe ASCII characters with a "%" followed by two hexadecimal digits.
URLs cannot contain spaces. URL encoding normally replaces a space with a plus (+) sign or with %20.
The URL interpreter is confused to see a % without hexadecimals after it.
Why would you think of solving by changing Nginx configuration???
It's impossible to solve from the server side. It's a problem from the client side.
https://headteacherofgreenfield.wordpress.com/2016/03/23/100-celebrations/
In that URL, the title is 100% Celebrations! but the permalink is autogenerated to 100-celebrations. It's because they know putting 100% will cause a URL encode problem.
If even Wordpress doesn't do it your way, then why should you do it?
I am using the PHP HybridAuth library and integrating oauth2 support, all providers such as Yahoo, MSN and Facebook works, except Google, showing
The redirect URI in the request:
https://www.example.com/auth?action=callback&hauth.done=Google did not match a registered redirect URI.
My redirect url is : https://www.example.com/auth?action=callback&hauth.done=Google, I've added both urls to see if I can workaround for their non sense escape limitation, e.g.
https://www.example.com/auth?action=callback&hauth.done=Google
https://www.example.com/auth?action=callback&hauth.done=Google
Still no luck...Any idea?
just an assumption, try urlencode()'ing the url,
$url = "https://www.example.com/auth?action=callback" . urlencode("&hauth.done=Google");
You need use the PHP urlencode function.
urlencode — URL-encodes string
(PHP 4, PHP 5)
string urlencode ( string $str )
This function is convenient when encoding a string to be used in a query part of a URL, as a convenient way to pass variables to the next page.
Example:
$encoded_url = urlencode("https://www.example.com/auth?action=callback&hauth.done=Google");
More informations:
HTML URL Encoding Reference
http://www.w3schools.com/tags/ref_urlencode.asp
PHP urlencode
http://php.net/manual/en/function.urlencode.php
I'm trying out http requests to download a pdf file from google docs using google document list API and OAuth 1.0. I'm not using any external api for oauth or google docs.
Following the documentation, I obtained download URL for the pdf which works fine when placed in a browser.
According to documentation I should send a request that looks like this:
GET https://doc-04-20-docs.googleusercontent.com/docs/secure/m7an0emtau/WJm12345/YzI2Y2ExYWVm?h=16655626&e=download&gd=true
However, the download URL has something funny going on with the paremeters, it looks like this:
https://doc-00-00-docs.googleusercontent.com/docs/securesc/5ud8e...tMzQ?h=15287211447292764666&\;e=download&\;gd=true
(in the url '&\;' is actually without '\' but I put it here in the post to avoid escaping it as '&').
So what is the case here; do I have 3 parameters h,e,gd or do I have one parameter h with value 15287211447292764666&ae=download&gd=true, or maybe I have the following 3 param-value pairs: h = 15287211447292764666, amp;e = download, amp;gd = true (which I think is the case and it seems like a bug)?
In order to form a proper http request I need to know exectly what are the parameters names and values, however the download URL I have is confusing. Moreover, if the params names are h,amp;e and amp;gd, is the request containing those params valid for obtaining file content (if not it seems like a bug).
I didn't have problems downloading and uploading documents (msword docs) and my scope for downloading a file is correct.
I experimented with different requests a lot. When I treat the 3 parameters (h,e,gd) separetaly I get Unauthorized 401. If I assume that I have only one parameter - h with value 15287211447292764666&ae=download&gd=true I get 500 Internal Server Error (google api states: 'An unexpected error has occurred in the API.','If the problem persists, please post in the forum.').
If I don't put any paremeters at all or I put 3 parameters -h,amp;e,amp;gd, I get 302 Found. I tried following the redirections sending more requests but I still couldn't get the actual pdf content. I also experimented in OAuth Playground and it seems it's not working as it's supposed to neither. Sending get request in OAuth with the download URL responds with 302 Found instead of responding with the PDF content.
What is going on here? How can I obtain the pdf content in a response? Please help.
I have experimented same issue with oAuth2 (error 401).
Solved by inserting the oAuth2 token in request header and not in URL.
I have replaced &access_token=<token> in the URL by setRequestHeader("Authorization", "Bearer <token>" )