简体   繁体   English

通过API .net C#订阅

[英]Subscribe through API .net C#

I have to submit subscription data to another website. 我必须将订阅数据提交到另一个网站。 I have got documentation on how to use this API however i'm not 100% sure of how to set this up. 我有关于如何使用此API的文档,但是我不是100%确定如何设置此API。 I do have all the information needed, like username / passwords etc. 我确实拥有所需的所有信息,例如用户名/密码等。

This is the API documentation: 这是API文档:

https://www.apiemail.net/api/documentation/?SID=4 https://www.apiemail.net/api/documentation/?SID=4

How would my request / post / whatever look like in C# .net (vs 2008) when i'm trying to acces this API? 当我尝试访问此API时,我的请求/帖子/在C#.net(与2008年相比)中将如何显示?

This is what i have now, I think i'm not on the right track: 这就是我现在所拥有的,我想我走的路不正确:

public static string GArequestResponseHelper(string url, string token, string username, string password)
{

HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(url);

myRequest.Headers.Add("Username: " + username);
myRequest.Headers.Add("Password: " + password);

HttpWebResponse myResponse = (HttpWebResponse)myRequest.GetResponse();
         Stream responseBody = myResponse.GetResponseStream();

         Encoding encode = System.Text.Encoding.GetEncoding("utf-8");
         StreamReader readStream = new StreamReader(responseBody, encode);

         //return string itself (easier to work with)
         return readStream.ReadToEnd();

Hope someone knows how to set this up properly. 希望有人知道如何正确设置它。 Thx! 谢谢!

The documentation doesn't state clearly if the credentials should be passed as HTTP headers. 该文档没有明确说明是否应将凭据作为HTTP标头传递。 They talk about parameters , so I would also try passing them as GET parameters: 他们谈论参数 ,所以我也尝试将它们作为GET参数传递:

url = string.Format("{0}?Username={1}&Password={2}", url, username, password);
HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(url);

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

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