Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I'm trying to submit a form made in unity via WebRequest, but i always get a 404 error. I even wrote a C# WinForm that also submit a form and it works. Do I need to do something specific in Unity for this to work ?

code that send the request.

public string SendRequestPost2(string link, Dictionary<string,string> parameters)
{
  using (var wb = new WebClient())
  {
    var data = new NameValueCollection();
    var stringValue = string.Empty;
    foreach (var parameter in parameters)
    {
      data[parameter.Key] = parameter.Value;
    }

    var msg = String.Format("[{0}], Sending POST request, Link : {1}, Parameters: {2}", DateTime.Now, link, stringValue);
    Logging.LoggingService.LogDebug(msg);

    var response = wb.UploadValues(link, "POST", data);
    var s = wb.Encoding.GetString(response);
    return s;
  }
}

enter image description here

share|improve this question
    
I'm not familiar with this WebClient class. I do this using WWW objects and coroutines. –  jhocking Mar 10 at 13:26

1 Answer 1

As you're getting a 404-error my best guess would be that you're posting to a broken link.

For more help I need to know more details about your code and the arguments you're giving the SendRequestPost2-method.

You can also try the first answer to this question: http://answers.unity3d.com/questions/11021/how-can-i-send-and-receive-data-to-and-from-a-url.html#

share|improve this answer
    
The link is not broken i managed to output the full link in a doc file and copy/paste link in my browser and it worked. –  PL Audet Mar 10 at 14:59
    
are you using a proxy in your browser? answers.unity3d.com/questions/801602/… –  vinzBad Mar 10 at 15:46
    
if you dont want to disclose the link + post parameters, you can use httpbin.org for testing –  vinzBad Mar 10 at 15:51
2  
I managed to make this works. Apparently my webserver detect Unity as if it was from another domain. That's where the cross-domain error from the stack trace come from. I had to add crossdomain.xml to allow Unity to make the query. Thanks for your help guys –  PL Audet Mar 10 at 19:25
    
Do you use the new Unity -> WebGL export? –  vinzBad Mar 11 at 10:46

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.