简体   繁体   English

如何过帐到不接受SOAP的Web服务

[英]How to POST to a webservice that doesn't accept SOAP

I am currently trying to send a compiled token to the web service which requires the token but I am unable to do it using most .NET 4.5 classes. 我目前正在尝试将已编译的令牌发送到需要该令牌的Web服务,但是我无法使用大多数.NET 4.5类来做到这一点。

Every time I send any sort of HTTP POST request to the server, it is unable to read the information i send to it as apparently they do not accept any sort of connection which includes a SOAP call. 每次我向服务器发送任何形式的HTTP POST请求时,它都无法读取我发送给它的信息,因为它们显然不接受任何形式的连接,包括SOAP调用。

I have actively tried to see how else I could contact the server without the SOAP call but only way I could find was by including the token inside the HTML and posting with Javascript. 我一直在积极尝试,看看不用SOAP调用我还能如何与服务器联系,但我唯一能找到的方法就是将令牌包含在HTML中并用Javascript发布。 For obvious reasons I don't want to use this method as its not secure. 由于明显的原因,我不想使用此方法,因为它不安全。

public void sendHTTPPost(string token)
{
    ServicePointManager.SecurityProtocol = (SecurityProtocolType)3072;
    var client = new RestClient("DOMAIN");
    var request = new RestRequest("URLEXTRA", Method.POST);
    var tokenToBytes = Encoding.ASCII.GetBytes(token);
    string encodedToken = System.Convert.ToBase64String(tokenToBytes);
    request.AddParameter("TOKEN", encodedToken);
    var response = client.Execute(request);
    Response.Write(response.Content);
}

The server should be able to see the data but as mentioned, the server doesn't accept any POST methods with a SOAP binding. 服务器应该能够看到数据,但是如上所述,服务器不接受任何带有SOAP绑定的POST方法。

Are there any other ways I would be able to contact this service via .NET without the use of the SOAP call/binding? 在不使用SOAP调用/绑定的情况下,还有其他方法可以通过.NET与该服务联系吗?

If it expects a simple http post with a parameter you can use a WebRequest client in .net rather than rest client. 如果期望带有参数的简单http帖子,则可以在.net中使用WebRequest客户端,而不是rest客户端。

https://docs.microsoft.com/en-us/dotnet/framework/network-programming/how-to-send-data-using-the-webrequest-class https://docs.microsoft.com/en-us/dotnet/framework/network-programming/how-to-send-data-using-the-webrequest-class

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM