How to emulate CURL with a WWW call in Unity3d

I’m using Unity 4.5, and build toward Flash.

In that setting, the Parse Plugin for Unity is not supported.
However, I think it should be possible to use Parse via its REST-API.

For that, I’m missing a piece of the puzzle:
How to pass multiple data specified as “-G --data-urlencode” via Unity’s WWW call?

For example, I can sign in a user at Parse with the curl command (at the commandline) that is constructed as:

string strCurl = "curl -X GET ";
strCurl += "-H "X-Parse-Application-Id: {APP_ID}" ";
strCurl += "-H "X-Parse-REST-API-Key: {APP_KEY}" ";
strCurl += "-H "X-Parse-Revocable-Session: 1" ";
strCurl += "-G --data-urlencode ‘username={Username}’ ";
strCurl += "–data-urlencode ‘password={Password}’ ";
strCurl += “https://api.parse.com/1/login”;

strCurl = strCurl.Replace(“{APP_ID}”,strAppId);
strCurl = strCurl.Replace(“{APP_KEY}”,strRestApiKey);
strCurl = strCurl.Replace(“{Username}”,strUsername);
strCurl = strCurl.Replace(“{Password}”,strPassword);

Now, I’d like to mimic this CURL call from Unity.

Right now, I’ve got as far as:

WWWForm form = new WWWForm();

string strUrl = “https://api.parse.com/1/login”;
form.headers[“Method”] = “GET”;
form.headers[“X-Parse-Application-Id”] = strAppId;
form.headers[“X-Parse-REST-API-Key”] = strRestApiKey;
form.headers[“X-Parse-Revocable-Session”] = “1”;

var headers = form.headers;
WWW download = new WWW( strUrl, new byte[ ]{0}, headers );

Obviously, the dummy byte array I’m passing should be replaced with something that represents next lines of the curl example:
strCurl += "-G --data-urlencode ‘username={Username}’ ";
strCurl += "–data-urlencode ‘password={Password}’ ";

Does anyone know how that can be done?

URL encoding usually means passing those values in the URL itself rather than in your post data array. The ‘URL Encoding’ part means removing any invalid URL characters so it can be transmitted properly. For example, if your username was ‘Bob Smith’ you could pass it to the Unity function ‘EscapeURL’ and get back ‘Bob%20Smith’

I would imagine that your final url might look something like this:

https://api.parse.com/1/login?username=Bob%20Smith&password=My%20Password

If that doesn’t work you could always set up a PHP or Javascript function on a server that would retrieve the data for you. You could then just pass your data to the script and it could use CURL to get it.

EDIT: It looks like the parse site is using http authentication so passing the username and password in the URL probably won’t work

up
I need to do this with UnityWebRequest for -u <use_id>:<use_password>

I don’t think WWW will work, as whenever WWWForm is passed to it, it will use POST method rather than GET.
UnityWebRequest is usable for it, as you get select GET method and still send WWWForm.

Add username and password as fields to WWWForm. You can setup everything as POST request, but before sending change .method to GET.

using a user name and password before the domain name with an @ sign in an url are just convention in browsers. They actually translate this into an Authorization header for basic authentication.

Thank you, Bunny83
If i understand right - I need url like “UserName@Password@http/www.example.com/some_page”?
Or “http/www.example.com/some_page@UserName@Password”?

Some google say that
http://user_name:password@www.example.com/some_page

And this is solution for me!