How to convert a curl query to wwwform

I’m working on Image recognition and have never worked with curl or wwwform. Can somebody help me send this query from unity.

curl -X POST -F image=@images/image.jpg -H 'Authorization: Token ’ -H ‘Accept: application/json’ https://query-api.kooaba.com/v4/query

This is what i did

WWWForm form = new WWWForm();

form.headers[“Method”] = “POST”;

form.headers[“Authorization”] = “gaveMyToken”;

form.headers[“Accept”] = “applicaton/json”;

form.headers[“Date”] = System.DateTime.Now.ToString(“ddd, dd MMM yyyy HH:mm:ss zzz”);

form.AddBinaryData(“fileUpload”, bytes, “images.png”, “images/”);

WWW w = new WWW(“https://query-api.kooaba.com/v4/query”, form);

The response is “Authorization header missing.”

Any help would be appreciated.

Thanks.

Your problem is that form.headers is just a property that “returns a Hashtable with the default headers”, but the form class itself doesn’t have a headers field internally. (That design is very strange btw).

That’s how the headers property looks like:

public Hashtable headers
{
	get
	{
		Hashtable hashtable = new Hashtable();
		if (this.containsFiles)
		{
			hashtable["Content-Type"] = "multipart/form-data; boundary=\"" + Encoding.UTF8.GetString(this.boundary) + "\"";
		}
		else
		{
			hashtable["Content-Type"] = "application/x-www-form-urlencoded";
		}
		return hashtable;
	}
}

The WWW constructor with a WWWForm looks like this:

public WWW(string url, WWWForm form)
{
	this.InitWWW(url, form.data, WWW.FlattenedHeadersFrom(form.headers));
}

So you have to get a local copy of your form.headers after you added all fields to the form and then use WWW like this:

//[...]
var headers = form.headers;
// add additional headers here
new WWW("https://query-api.kooaba.com/v4/query", form.data, headers);

Thanks Man it worked.