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 /
This question was closed Oct 18, 2016 at 11:43 AM by RangerDog for the following reason:

Other

avatar image
0
Question by RangerDog · Oct 18, 2016 at 07:53 AM · apiwebconnection

Multiple Errors while connecting to Webapi, No errors in VS Studio

Hai! So i got this code from someone from websites, I edited it so that it all works fine. In Visual Studio it doesn't give an error, (errors down the code), Code: (Censored website and such)

 using UnityEngine;
 using System;
 using System.Collections.Generic;
 using System.Net;
 using Newtonsoft.Json;
 using System.Threading.Tasks;
 using System.Net.Http;
 
 public class GetOnlineContainers : MonoBehaviour
 {
     protected string username = "**************";
     protected string password = "**************"";
     protected string connection = "**************"";
     protected string accessToken = "**************"";
 
     public GetOnlineContainers()
     {
         HttpWebRequest req = WebRequest.Create("**************"")
                              as HttpWebRequest;
 
         var client = new System.Net.Http.HttpClient { BaseAddress = new Uri("**************"") };
         client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", accessToken);
         
         var result = Post("/api/public/token", GetTokenFormContent(username, password, connection), false).Result;
         Debug.Log(JsonConvert.DeserializeObject<TokenResult>(result));
     }
 
 
     private static System.Net.Http.FormUrlEncodedContent GetTokenFormContent(string username, string password, string connection)
     {
         return new System.Net.Http.FormUrlEncodedContent(new[]
         {
             new KeyValuePair<string, string>("grant_type", "password"),
             new KeyValuePair<string, string>("username", username),
             new KeyValuePair<string, string>("password", password),
             new KeyValuePair<string, string>("connection", connection)
         });
     }
 
     private async Task<string> Post(string url, HttpContent content, bool requireAuthorization)
     {
         using (var client = new System.Net.Http.HttpClient { BaseAddress = new Uri(string.Empty) }) //GetBaseUrl()) })
         {
             if (requireAuthorization)
             {
                 //var accessToken = GetAccessToken();
                 //if (!string.IsNullOrEmpty(accessToken))
                 //{
                 //    client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", accessToken);
                 //}
             }
             var response = await client.PostAsync(new Uri(url, UriKind.RelativeOrAbsolute), content);
             return await response.Content.ReadAsStringAsync();
         }
     }
 
     public class TokenResult
     {
         [JsonProperty("access_token")]
         public string AccessToken { get; set; }
 
         [JsonProperty("token_type")]
         public string TokenType { get; set; }
 
         [JsonProperty("expires_in")]
         public int ExpiresIn { get; set; }
 
         [JsonProperty("userName")]
         public string UserName { get; set; }
 
         [JsonProperty("error")]
         public string Error { get; set; }
 
         [JsonProperty("error_description")]
         public string ErrorDescription { get; set; }
     }
 }


Errors:

 Assets/GetOnlineContainers.cs(40,24): error CS0081: Type parameter declaration must be an identifier not a type

 Assets/GetOnlineContainers.cs(40,35): error CS1519: Unexpected symbol `Post' in class, struct, or interface member declaration

 Assets/GetOnlineContainers.cs(40,32): error CS1520: Class, struct, or interface method must have a return type

 Assets/GetOnlineContainers.cs(52,39): error CS1525: Unexpected symbol `client'

 Assets/GetOnlineContainers.cs(53,33): error CS1525: Unexpected symbol `response'

The first 2, to be honest i have no idea what could be wrong with it. The third one, there is a return on the using, but that's on the wrong level. The 4th and 5th, not sure what could be wrong there, considering its the correct syntax.

If anyone could explain what's going wrong here, would be awesome!

Comment
Add comment
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

0 Replies

  • Sort: 

Follow this Question

Answers Answers and Comments

57 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

Related Questions

Networking UNet: Why can we have multiple NetworkClient and how NetworkBehaviour knows which one to use? 1 Answer

Real Time Refresh from Web Portal 0 Answers

How can I upload image with data using post api and how to get the response ? 1 Answer

MySql On Web ? 1 Answer

Is it possible to send and recieve data from/to a MySql server? 4 Answers


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