我想将服务集成到我的项目中。在他们糟糕的文档中,它说
Headers:
POST /avia.php HTTP/1.1
Host: www.tpg.ua
Connection: Keep-Alive
User-Agent: PHP-SOAP/7.2.16
Content-Type: text/xml; charset=utf-8
SOAPAction: "http://www.tpg.ua/avia.php#getCities"
Content-Length: 395
Authorization: Basic here_your_basic_auth_token
Body:
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:SOAP-
ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns1="http://www.tpg.ua/avia.php"
xmlns:xsd="http://www.w3.org/2001/XMLSchema" SOAP-
ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP-ENV:Body>
<ns1:getCities />
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
我尝试将其转换为c#代码
我得到了这样的基本令牌,这是可行的,它给了我一个代币字符串
var token = new System.Net.Http.Headers.AuthenticationHeaderValue("Basic", Convert.ToBase64String(Encoding.UTF8.GetBytes($"{username}:{password}")));
然后我想使用该令牌获取数据,但响应为null 我的代码有什么问题?
var httpWebRequest = (HttpWebRequest)WebRequest.Create("http://www.tpg.ua/avia.php#getCities");
httpWebRequest.ContentType = "application/xml";
httpWebRequest.Method = "POST";
httpWebRequest.Headers.Add("Authorization", "Basic " + token);
var myWebResponse = httpWebRequest.GetResponse();
var responseStream = myWebResponse.GetResponseStream();
if (responseStream == null) return null;
var myStreamReader = new StreamReader(responseStream, Encoding.Default);
var json = myStreamReader.ReadToEnd();
responseStream.Close();
myWebResponse.Close();