所以我想用request.Credentials
功能和構建解決方案後,我有以下錯誤..無效令牌「=」在類,結構或接口成員聲明
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using System.Web.Caching;
namespace com.tortoise.Controllers
{
public class VebraController : ApiController
{
public class HttpHeader
{
string username = "foo";
string password = "foo";
string url = "www.test.com";
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
.
NetworkCredential myCredentials = new System.Net.NetworkCredential(username,password);
string usernamePassword = (username + password);
cache = new CredentialCache();
//Invalid Token '=' in class,struct,interface member declaration, also for CredentialCache > //Method must have a return type.
CredentialCache cache.Add(Uri url); "Basic",myCredentials);
//Invalid token "Basic" in class,struct,or interface member declaration, same with the ')'.
request.Credentials = CredentialCache cache;
//Invalid Token '=' in class,struct,interface member declaration
request.Headers.Add("Authorization", "Basic " +
//Invalid Token '(' in class,struct,interface or declaration
Convert.ToBase64String(Encoding.ASCII.GetBytes(usernamePassword));
//Invalid Token '(' in class,struct,interface or declaration same for GetBytes. and end of usernamePassword
// Get the token from the response:
string token = response.GetResponseHeader("Token");
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
response.Write (response.StatusCode) ;
//Invalid Token '(' in class,struct,interface or declaration same for ')'
}
我已經包括錯誤在上面的代碼中收到。希望他們能夠提高我擁有的問題的清晰度。
我相信你是直接在類的級別編寫代碼,因爲它看起來應該在一個方法內。 – Habib 2014-09-29 13:39:33
@ Selman22 這就是以上內容: CredentialCache cache = new CredentialCache(); CredentialCache cache.Add(Uri url); 「基本」,myCredentials); – SavageDragon87 2014-09-29 13:42:19
只需刪除CredentialCache一詞。爲什麼不使用我在之前的問題中已經給你的代碼?這個問題已經爲你解答了...... – 2014-09-29 13:43:11