My url string is
"https://MyCom.Produect.App.ResourcePath/ts?Customer_Account=A B C\, LLC,D E F\, LLC&Billing_Code=11,12&fromDateTime=2013-05-13&toDateTime=2013-06-13"
If I copy it in IE and run, it will return some data. However the same string in c# gives me a bad request exception. Here is my c# code for this, I think I must miss something. Thanks
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);
}
}
m_strUrl
? Are you using the@
sign to make the string literal? If not it is trying to escape the commas\,
. – Evan lewis yesterdaym_strUrl
variable? – Evan lewis yesterday