Sharekit: url is modified while posting to facebook? - iphone

I am posting image with image title and in the image title I have added url, I am able to share image and url also but,there is slight modification in the url.The = symbol is converted to %3D ,as shown below the both URLs(dummy url).
posted URL:
http://....=418ioekVlhTIu2sr9qpdAQ==
 
URL on Facebook
http://...=418ioekVlhTIu2sr9qpdAQ%3D%3D
So is there any better way to post url and image in one post only or
help me so that by doing some change in the code I should be able to share correct url in the Image title itself.

This happens because the URL format converts it's reserved special characters to HTML entity codes (percent escaping) as shown in here:
http://www.w3schools.com/tags/ref_urlencode.asp
you have 2 options to pass the URL string correctly:
On the receiver side (after the URL Request is sent by the client), decode the URL string that you received, this will normalize the string back to normal.
Use the POST method of html instead of the GET method to store your parameters. although I'm not sure you have an option for that.
On the iOS obj-c, Conversion between URL Percent escapes is done like so-
[normalText stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
[encodedText stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
Just for fun:
You can enter a URL and see it's encoded/decoded value on this website: http://meyerweb.com/eric/tools/dencoder and see how it works in practice.

Related

Why is Response.Redirect UrlEncoding some parts of the well-formed URL it is supplied?

I have a tiny (Classic) ASP file being used for a redirect. I want to send the user to a URL that may have some characters in (I'm taking this from the incoming URL, as it's redirecting all paths from domainA to domainB, but I've hard-coded it here to simplify things).
Here's an example URL, as it comes to the the redirect script:
https://old.example.org/my%20test/?name=Danny%20Tuppeny
The URL contains two spaces, which I am certain are both encoded correctly. If you paste the URL into your browser with literal spaces, both will be converted to %20 by the browser.
I'm passing this url to Response.Redirect (hard-coded here for simplicity):
<%
Response.Redirect "https://new.example.org/my%20test/?name=Danny%20Tuppeny"
%>
However the location header being output has one of the %20's encoded again, and looks like this:
Location: https://new.example.org/my%2520test/?name=Danny%20Tuppeny
This is unexpected! This has been asked before but all answers (including the excepted one) appear to be incorrect. I do not believe I should be randomly decoding parts of a valid URL to offset what appears to be unexpected/undesirable behavior from ASP.
The docs make no mention of this behavior (they even say "Always validate and encode the URL that is passed to Response.Redirect"), and even worse, have samples on how to apply HTML encoding to values being passed to Response.Redirect which seems even more incorrect.
Note: ASP.NET does not have this stupid behaviour.
Is there a way to pass a well-formed URL to Response.Redirect and have it do what is expected?
To work around the encoding issue you can add a Location header to perform the redirection. No encoding will be applied to the URL.
Response.Status = "302 Moved Temporarily" ''// or use whatever status code is appropriate
Response.AddHeader "Location", "https://new.example.org/my%20test/?name=Danny%20Tuppeny"

I'm having a lot of trouble with Facebook OAuth

I have created a class that generates a URL that authorized my users with Facebook. Here it is:
https://www.facebook.com/dialog/oauth?response_type=code&client_id=...&scope=email%2Cuser_about_me%2Cuser_friends%2Cuser_hometown%2Cuser_location%2Cuser_work_history%2Cuser_education_history%2Cpublish_actions&state=...&redirect_uri=http%3a%2f%2flocalhost%3a53016%2fsocial%2fcallback%3fvariables%3dY2FsbGJhY2tfdXJsOi9MYW5kaW5nO2ZhbGxiYWNrX3VybDovQ29uc3VsdGFudC9TaWduVXA7bWV0aG9kOjE7cHJvdmlkZXI6MQ%3d%3d
This URL works just fine and returns back to my callback function. I'm able to convert the base64 string to my variables that I pass along with my URL. The trouble that I am facing is that Facebook doesn't recognize the URL to give me the access_token. This the return URL that I send to Facebook for the access_token.
https://graph.facebook.com/oauth/access_token?client_id=...&client_secret=...&code=...&redirect_uri=http%3a%2f%2flocalhost%3a53016%2fsocial%2fcallback%3fvariables%3dY2FsbGJhY2tfdXJsOi9MYW5kaW5nO2ZhbGxiYWNrX3VybDovQ29uc3VsdGFudC9TaWduVXA7bWV0aG9kOjE7cHJvdmlkZXI6MQ%3d%3d
(I have cleared out the client_id and client_secret for obvious reasons.)
Can anyone notice what I am doing wrong here?
Perry thank you for your help. I was able to figure out what the problem was on my project. When I was encoding my parameters to Base64 I wasn't using the proper methods to convert it to String. This answer on stackoverflow helped me figure out what I was doing wrong.
C# Method like Base64String, but only alphanumeric (no plus or slash)
The answer in particular is from Mason G. Zhwiti. I was just doing Convert.Base64String instead of HttpServerUtility.UrlTokenEncode(byte[] b). After I did that I was able to get my response. I seemed that my URL had two equal symbols at the end. That was throwing off Facebooks URL validation. Once I did the appropriate method it started working.
I hope this helps anyone else who is struggling with this type of problem.
What is the specific error message - was it unauthorized redirect_uri?
I'm kind of oblivious to the variables - what are they for?
It doesn't seem like you should be doing the callback to a querystring URL, but maybe that's OK. When I first implemented OAuth2, I had the API calls originate from and callback to specific URLs for each provider, such as mysite.com/login-google.php or mysite.com/login-facebook.php, but now I have the callbacks point to the main site URL (mysite.com). Since we have index.php at the main site URL, we can intercept the callback in index.php and route them to the desired provider script (login-google.php or login-facebook.php) which cleans up the callback URLs and makes them a no-brainer for end-users to work with.
Your callback URL:
http://localhost:53016/social/callback?variables=Y2FsbGJhY2tfdXJsOi9MYW5kaW5nO2ZhbGxiYWNrX3VybDovQ29uc3VsdGFudC9TaWduVXA7bWV0aG9kOjE7cHJvdmlkZXI6MQ==
Can you access that callback URL in a browser? Code it up to throw an error or output a debug message so you know the callback URL is working.
I've documented the OAuth2 flow for Facebook quite cleanly in this code: https://github.com/perrybutler/WP-OAuth/blob/master/login-facebook.php
Hope it all helps...

RESTful semantics for different mechanisms

Imagine I am creating an API to allow a user to attach an image to their profile, where the image may come from a binary submission in the body, or a url, which the server will retrieve and process.
Assuming the API expects a PUT with binary image data to
/user/jon/image
When adding the URl functionality, which of the following would be preferable?
A:
PUT to /user/jon/image/url
passing the url in the body
or
B:
PUT /user/jon/image/
passing in a url in the body and setting a MIME type to advise the host whether or not the content is an image or an URL?
Is there a standard way of dealing with this situation? I feel that using MIME types to dictate the payload is more semantically correct, but a little less discoverable
Thanks
Once I had this same problem. I solved it by first posting the image by "PUT /user/jon/image/" and then posting the URL with PUT to /user/jon/image/url.
The problem is, that the user posts an image and forgets about the URL. I solved this by saving the image temporally in a session and when the URL is posted, I saved the URL and the image at the same time.
Problem is, this is not Restful, because a restful server doesn't have sesions. But being 100% restful is almost imposible, so its your choice.

how to send data to server using get request

I want to send data to server when user fill ups the from in iphone , i used
NSURLRequest
but it returns with bad url when spaces are coming in the from data
any help please
if what you want is just send a form over GET, a possible way is:
NSString* urlWithParams = #"http://xxxxxxxxxx.com/xxxxx/xxxxxx/mobile.php?method=createOrder&sid=dfdk6figau1reagpdv9sc6po67&dnumber=ali.jamali&odate=2011-05-21&ordate=2011-05-21&oshipto=shipopingto&otype=emergency&oatype=&oref=refrence&oshipvia=Shipping";
NSString* escapedUrl = [urlWithParams stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
now use escapedUrl as the URL for your NSURLRequest.
If you need help with the request just tell me. Based on your comments, i see your problem was just the encoding.
Okay, a couple of things. First one: why are you using a GET? A POST is sort of canonical for sending data, like from a form.
Second: are you converting the URL to net form? That is, the non-address characters to their %-sign forms, like %20 for a space?

Special characters in Password are converting URL into a String

Special characters in Password are converting URL into a String and truncating the URL after the password in the URL .
Here is what I am using
webbrowser.navigate("http://username:pww#word#www.something.com")
when I see the above request in the VS browser it is like ..
http://username:pww
and the result is "Page Not Found "
When there is no special character in the password the link goes fine without any issues ..Please Help Thanks In Advance
webbrowser.navigate("http://username:pww%40word#www.something.com")
Please use HTTP POST instead of HTTP GET to send passwords to your website. Special characters don't matter so much with POST, and it's somewhat more secure (user's neighbor can't see the password in the URL bar).
If you must use GET, URL-encode the password. For example, you can replace "#" with "%40". For C#, see HttpUtility.UrlEncode. You'll probably need to encode username and password separately, and then build the URL.