Search Unity

WWW using CONNECT instead of POST?

Discussion in 'Scripting' started by mhobbs_GTDC, Feb 17, 2014.

  1. mhobbs_GTDC

    mhobbs_GTDC

    Joined:
    Feb 6, 2014
    Posts:
    6
    Hi,

    I'm using WWW to call a RESTful api (azure table storage) but I when I attempt to POST to the server Fiddler shows that CONNECT is being used and the url is slightly wrong.

    I'm using the following:

    Code (csharp):
    1.        
    2. public static WWW PostDataOnServer(string url, byte[] data, Dictionary<string, string> headers)
    3.         {
    4.             Debug.Log("Posting data to: " + url);
    5.             return new WWW(url, data, headers);
    6.         }
    7.  
    Where the url= https://myAccount.table.core.windows.net/Tables
    The byte data is a UTF8 encoded version of the following string:
    Code (csharp):
    1.  
    2. "{
    3.     "TableName":"TableTest"
    4. }"
    5.  
    And I'm using the following headers: Date, x-ms-version, Content-Type, Content-Length, Authorization.

    Fiddler shows that WWW is sending the following:

    Code (csharp):
    1.  
    2. CONNECT myAccount.table.core.windows.net:443 HTTP/1.1
    3. Host: myAccount.table.core.windows.net:443
    4. User-Agent: UnityPlayer/4.3.4f1 (http://unity3d.com)
    5. Proxy-Connection: Keep-Alive
    6. Authorization: SharedKeyLite myAccount:mysharedKey=
    7. Content-Length: 28
    8. Content-Type: application/json
    9. Date: Mon, 17 Feb 2014 11:40:31 GMT
    10. x-ms-version: 2013-08-15
    11.  
    That first line should be reading as:

    Code (csharp):
    1.  
    2. POST https://myAccount.table.core.windows.net/Tables HTTP/1.1
    3.  
    The host address shouldn't be showing port 433 either. I've double checked that the correct address is going in (you'll see the Debug.Log in the method which prints out the correct url as it goes into the new WWW).

    Using GET (by not including data in when creating the WWW) works fine and doesn't alter the url or insert an incorrect verb.

    Any ideas why it's not calling the POST verb and why my url is being altered by WWW?

    Best Regards
    Hobsie
     
  2. Patico

    Patico

    Joined:
    May 21, 2013
    Posts:
    886
    Maybe you should use WWWForm for POST requests? If I remember correctly WWW class makes GET requests.
     
  3. mhobbs_GTDC

    mhobbs_GTDC

    Joined:
    Feb 6, 2014
    Posts:
    6
    Thanks for responding.

    According to this: http://docs.unity3d.com/Documentation/ScriptReference/WWW-ctor.html

    WWW uses GET by default and POST when you give it something for postData.

    WWWForm is for setting up Form data to give to WWW (WWWForm isn't actually used to send HTTP requests).

    Really scratching my head over this.

    Regards
    Hobsie
     
  4. mhobbs_GTDC

    mhobbs_GTDC

    Joined:
    Feb 6, 2014
    Posts:
    6
    Lol ok this is great.

    It turns out that my using Fiddler to intercept the WWW call has some sort of affect on the call (seems fine for GET). I just tried this again with Fiddler turned off and it return OK and created the table as expected!

    So I guess the question now is why did Fiddler cause the call to change? (a question that might not be within the remit of this forum).
     
unityunity