C#シミュレーション発行Getリクエスト
1922 ワード
/// <summary>
/// Get
/// </summary>
/// <param name="url"> url</param>
/// <param name="content"> </param>
/// <param name="headers">header </param>
/// <param name="encode"> , null, UTF8 </param>
/// <returns> </returns>
public string Get(string url, NameValueCollection content, NameValueCollection headers, Encoding encode)
{
string remoteInfo;
var webClientObj = new WebClient { Encoding = encode ?? Encoding.UTF8 };
webClientObj.Headers.Add(headers);
try
{
webClientObj.QueryString.Add(content);
return webClientObj.DownloadString(url);
}
catch (Exception ex)
{
remoteInfo = ex.ToString();
}
return remoteInfo;
}
呼び出し例:
string getURL = string.Format("http://{0}/services/sessions/{1}", this.PASSPORT_SERVER, token);
NameValueCollection content = new NameValueCollection();
content.Add("X-LITB-Correlation-ID", this.ACCESS_KEY+System.Guid.NewGuid().ToString());
//content.Add("Authorization", GetAuthToken(this.ACCESS_KEY, this.ACCESS_PASSWORD));
NameValueCollection head = new NameValueCollection();
head.Add("ContentType", "text/xml; charset=UTF-8");
head.Add("Accept", "application/xml");
head.Add("MediaType", "application/xml");
head.Add("Authorization", GetAuthToken(this.ACCESS_KEY, this.ACCESS_PASSWORD));
string userInfoXML = Get(getURL, content, head, null);
ありがとう:Tea楊が提供した方法!