代码之家  ›  专栏  ›  技术社区  ›  Younes

通过api.net c订阅#

  •  0
  • Younes  · 技术社区  · 14 年前

    我必须向其他网站提交订阅数据。我有关于如何使用这个API的文档,但是我不完全确定如何设置这个API。我有所有需要的信息,比如用户名/密码等。

    这是API文档:

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

    当我尝试访问这个API时,我的请求/帖子/在C.NET(与2008年相比)中的任何内容看起来如何?

    这就是我现在拥有的,我想我走错了道路:

    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();
    

    希望有人知道如何正确设置。谢谢!

    1 回复  |  直到 14 年前
        1
  •  1
  •   Darin Dimitrov    14 年前

    文档没有明确说明是否应该将凭据作为HTTP头传递。他们谈论 parameters ,因此我还尝试将它们作为get参数传递:

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