Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
1
Question by cgraf1 · Jan 22, 2018 at 07:47 PM · apiwebrequestwwwformpost

API POST call works in POSTMAN but not in Unity

Hey everyone. In my project, after a player inputs their first name, last name, and email address, an API POST call is made sending these strings after being saved in variables. I have tested this call in POSTMAN and it works fine, but in Unity it gives me a "Generic / Unknown HTTP Error."

 IEnumerator AWSCall(){
 
          WWWForm test_form = new WWWForm();
          test_form.AddField("first_name", fName);
          test_form.AddField("last_name", lName);
          test_form.AddField("email_address", eMail);
 
          using (var w = UnityWebRequest.Post(AWS_URL, test_form)){
 
              yield return w.Send();
              if(w.isNetworkError || w.isHttpError){
 
                  print(w.error);
              }else{
 
                  print("Transfer Complete");
              }
          }


Anyone know what could be the issue? Thanks!

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image avorobjev · Jan 23, 2018 at 11:39 AM 0
Share

I have the same issue appeared in Unity 2017.3.0f3

3 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by avorobjev · Jan 23, 2018 at 11:42 AM

It looks like it's a bag https://forum.unity.com/threads/post-requests-doesnt-work-in-2017-3.510281/ https://issuetracker.unity3d.com/issues/networking-unitywebrequest-dot-post-returns-generic-slash-unknown-http-error

I changed my methods from WWW to UnityWebRequest like this:

  IEnumerator Post()
  {
             string postData = "{....post data json...}";
             byte[] bytes = GetBytes(postData);
             using (UnityWebRequest www = UnityWebRequest.Put("http://localhost/api/PutMethod", rawData))
             {
                 www.SetRequestHeader("Content-Type", "application/json");
                 www.SetRequestHeader ("Accept", "text/json");
     
                 yield return www.Send();
     
                 if (www.isNetworkError)
                 {
                     Debug.Log(www.error);
                 }
                 else
                 {
                     Debug.Log(www.downloadHandler.text);
                 }
             }
     }
Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image cgraf1 · Jan 23, 2018 at 03:03 PM 0
Share

Yep. I basically had to do the same thing. $$anonymous$$ade a Json file and class. The inputs from the player changed the values in the class and then used the UnityWebRequest.

avatar image cgraf1 cgraf1 · Jan 23, 2018 at 07:53 PM 0
Share

I have a new issue now, wonder if anyone can help out. The POST call when successful is supposed to return 2 ID numbers in the form of a JSON. So they are like this:

{ "opp_id": "006f4000005XIN0AAO", "hiker_id": "a04f4000001dvd$$anonymous$$AAQ" }

When I try to access them with www.downloadHandler.text, sometimes I get {"error":"List has no rows for assignment to SObject"}. Other times I can see them, but then it doesn't work when I try to turn them into new strings and eventually work with them as variables. Any idea what is going on here?

avatar image
0

Answer by montacerdk · Apr 03, 2018 at 08:13 AM

Hey guys, I am trying to invoke a Web Service in Unity, it requires first an access token that i'll get it from this API : https://api.cognitive.microsoft.com/sts/v1.0/issueToken. I order to recieve the access token, I should use a POST request with a Ocp-Apim-Subscription-Key as a header and no data will be passed in the HTTP body, it works correctly with Postman, but in Unity, i get this Error :

 Error is : Generic/unknown HTTP error
 UnityEngine.Debug:Log(Object)
 <RequestToken>c__Iterator0:MoveNext() (at Assets/Scripts/Test.cs:26)
 UnityEngine.SetupCoroutine:InvokeMoveNext(IEnumerator, IntPtr)

This is my code :

 using System.Collections;
 using UnityEngine;
 using UnityEngine.Networking;
 
 public class Test : MonoBehaviour
 {
     public static readonly string accessUri = "https://api.cognitive.microsoft.com/sts/v1.0/issueToken";
     private string apiKey;
     private string accessToken;
 
     public void Doo ()
     {
         StartCoroutine(RequestToken());
     }
 
     public IEnumerator RequestToken()
     {
         UnityWebRequest request = new UnityWebRequest(accessUri, UnityWebRequest.kHttpVerbPOST);
         request.SetRequestHeader("Ocp-Apim-Subscription-Key", "a66ec1e2efed47639f22e2dc2e760d13x");
 
         yield return request.SendWebRequest();
 
         if (request.isNetworkError || request.isHttpError)
         {
             Debug.Log("Error is : " + request.error);
         }
         else
         {
             Debug.Log("downloadHandler Text : " + request.downloadHandler.text);
             Debug.Log("responseCode : " + request.responseCode);
             Debug.Log("isDone : " + request.isDone);
             Debug.Log("method : " + request.method);
         }
     }
 }

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by Tarrag · Apr 23, 2020 at 10:16 PM

Hey @montacerdk did you find a solution to this? cheers!

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

128 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Issue with sending Json via UnityWebRequest 0 Answers

Android Post ScreenShot to Facebook 0 Answers

php $_POST is blank when I send variables from unity 3 Answers

UnityWebRequest read body response 0 Answers

How to stay connected on a website to send WWWForm? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges