- Home /
Passing a curl user via WWWForm
There is a header field for WWW, but is there a way to pass a curl user via WWW or WWWForm?
Answer by Bunny83 · Jul 21, 2013 at 02:19 AM
There is nothing like a "cURL user". cURL is just a library / commandline tool for requesting / transferring data from / to a server.
I guess you actually want to add an Authorisation header to your request. You can use this helper class i've written some time ago which can be used to add an authorization header to the request headers.
// C#
public static class WWWHeaders
{
public static string CreateAuthorization(string aUserName, string aPassword)
{
return "Basic " + System.Convert.ToBase64String(System.Text.Encoding.ASCII.GetBytes(aUserName + ":" + aPassword));
}
public static Hashtable AddAuthorizationHeader(this Hashtable aHeaders, string aUserName, string aPassword)
{
aHeaders.Add("Authorization",CreateAuthorization(aUserName, aPassword));
return aHeaders;
}
}
Use it like this:
//C#
WWWForm form = new WWWForm();
// Add any fields you like / need
var headers = form.headers;
headers.AddAuthorizationHeader(UserName, Password);
WWW request = new WWW(YourURL, form.data, headers);
Is there a way to use this without having to pass in form.data (i.e. don't post any form data)
No, not with WWW. You can only make post requests with custom headers. That's a (strange) limitation of the WWW class the only other way is to use .NET classes to make the request.
Your answer
![](https://koobas.hobune.stream/wayback/20220613110526im_/https://answers.unity.com/themes/thub/images/avi.jpg)