A Method for Making Http Requests on Unity iOS

A method for making HTTP requests on Unity iOS?

I got threading to work on iOS- I believe it was crashing due to ghost threads or something. Restarting the device seems to have fixed the crashing so I'll just use WebRequest.HttpWebRequest with threads.

unity ios using https unable to make rest callout

I got it figured out. The issue was the url contained a % sign and ios apparently cant handle that.

UnityWebRequest not working in iOS

Found a solution. It turns out I had to specify in the Info.plist file that I want to allow "insecure" http connections for the iOS app.

<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
<key>NSExceptionDomains</key>
<dict>
<key>just-an-example.com</key>
<string></string>
</dict>
</dict>

Unity IOS app can't use UnityWebRequest to call self signed certificate HTTPS

A similar question has been asked here. Looks like you have to specify in the Info.plist file that you want to allow "insecure" http connections for the iOS app.

<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
<key>NSExceptionDomains</key>
<dict>
<key>just-an-example.com</key>
<string></string>
</dict>
</dict>

Unity 3D Puts/Deletes http methods

WebClient and WebRequest are both available in Unity and looks like it will only work with Pro Unity version just like any other API from the System.Net namespace. I don't know if this restriction has changed in Unity 5. They support all those restful calls mentioned in your question.

Unity Added a new API called UnityWebRequest in version 5.2 with mobile platform support in 5.3. It was designed to replace WWW and it supports all the restfull calls listed in your question. Below are example for each one. This is not a full example. You can find full examples in the link I provided above.

//Get
UnityWebRequest get = UnityWebRequest.Get("http://www.myserver.com/foo.txt");

//Post
UnityWebRequest post = UnityWebRequest.Post("http://www.myserver.com/foo.txt","Hello");

//Put
byte[] myData = System.Text.Encoding.UTF8.GetBytes("This is some test data");
UnityWebRequest put = UnityWebRequest.Put("http://www.my-server.com/upload", myData);

//Delete
UnityWebRequest delete = UnityWebRequest.Delete("http://www.myserver.com/foo.txt");

You can see complete example for each one including posting with json here.



Related Topics



Leave a reply



Submit