私のURL文字列は
" https://MyCom.Produect.App.ResourcePath/ts?Customer_Account=A BC\, LLC,DEF\, LLC&Billing_Code=11,12&fromDateTime=2013-05-13&toDateTime=2013-06-13"
IE にコピーして実行すると、何らかのデータが返されます。ただし、C# で同じ文字列を使用すると、不正なリクエスト例外が発生します。これが私のc#コードです。何かが欠けているに違いないと思います。ありがとう
public void GetDataAsyn(string m_strUrl)
{
var username = m_strEmail;
var password = m_strPassword;
var uri = new Uri(m_strUrl);
var credentialCache = new CredentialCache();
credentialCache.Add(uri, "Basic", new NetworkCredential(username, password));
var httpRequest = (HttpWebRequest)WebRequest.Create(uri);
httpRequest.Method = "GET";
httpRequest.ContentType = "application/json";
httpRequest.UseDefaultCredentials = true;
httpRequest.Accept = Constants.CONTENT_TYPE_TEXT_CSV;
httpRequest.UserAgent = Helper.GetUserAgent();
Helper.SetProxyIfNeeded(httpRequest, uri);
httpRequest.Headers.Add("Authorization", Helper.GetAuthHeader(username, password));
ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };
httpRequest.BeginGetResponse(GetResponseCallback, new object[] { httpRequest });
}
private void GetResponseCallback(IAsyncResult asyncResult)
{
try
{
var obj = (object[])asyncResult.AsyncState;
var request = (HttpWebRequest)obj[0];
var response = request.EndGetResponse(asyncResult);
Stream responseStream = response.GetResponseStream();
if (responseStream != null)
{
var streamReader = new StreamReader(responseStream);
ReturnedData = streamReader.ReadToEnd();
}
....do something with ReturnedData
}
catch (Exception ex)
{
Helper.LogError(ex);
}
}