I have problem with getting response from Web Services. I tried to find solution here, but without success.
Can someone help me with this, please?
Iam getting Error:
Error: System.Net.WebException: The remote server returned an error: (400) Bad Rquest.
I needed to remove links, because I can not post this question with them.
Thanks in advance!
Code:
private void CallWebService()
{
HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(link);
req.Referer = "link";
req.UserAgent =
"Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; WOW64; " +
"Trident/4.0; SLCC1; .NET CLR 2.0.50727; Media Center PC 5.0; " +
".NET CLR 3.5.21022; .NET CLR 3.5.30729; .NET CLR 3.0.30618; " +
"InfoPath.2; OfficeLiveConnector.1.3; OfficeLivePatch.0.0)";
HttpWebRequest httpreq = (HttpWebRequest)req;
httpreq.Method = "POST";
httpreq.ContentType = "text/xml; charset=utf-8";
req.ContentLength = 0;
httpreq.Headers.Add("SOAPAction: link");
StringBuilder soaprequest = new StringBuilder("<soap:Envelope xmlns:xsi=link"");
soaprequest.Append("xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" ");
soaprequest.Append("xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\"><soap:Body>");
soaprequest.Append("<getProductListDownloadXML xlmns=http://link>");
soaprequest.Append("<login>**</login>");
soaprequest.Append("<password>**</password>");
soaprequest.Append("<encoding>utf-8</encoding>");
soaprequest.Append("<onStock>false</onStock>");
soaprequest.Append("</getProductListDownloadXML></soap:Body></soap:Envelope>");
try
{
HttpWebResponse res = (HttpWebResponse)httpreq.GetResponse();
string response = res.GetResponseStream().ToString();
MessageBox.Show(response);
}
catch (WebException ex)
{
string error = ex.ToString();
if (!String.IsNullOrWhiteSpace(error))
{
MessageBox.Show(error);
}
}
}