【问题标题】:Posting to blogger via idHTTP通过 idHTTP 向博主发帖
【发布时间】:2014-02-21 10:29:36
【问题描述】:

我正在尝试使用 idHTTP 组件向 Blogger 发帖,但是,我收到“HTTP/1.0 400 Bad Request”错误。

首先,我得到了 Auth 代码,使用下面的代码可以完美地工作:

TStringList *request = new TStringList;
TStringList *response = new TStringList();

IdHTTP2->Request->Connection = "Keep-Alive";
IdHTTP2->Request->ContentType = "application/x-www-form-urlencoded";
IdSSLIOHandlerSocketOpenSSL1->SSLOptions->Method = sslvSSLv23;

request->Clear();
request->Values["accountType"] = "GOOGLE";
request->Values["Email"]       = "xxxxxxx@gmail.com";
request->Values["Passwd"]      = "yyyyyyy";
request->Values["source"]      = "test-test";
request->Values["service"]     = "blogger";

response->Text = IdHTTP2->Post("https://www.google.com/accounts/ClientLogin", request);
auth = response->Values["Auth"];  //working perfectly

然后,我获得了 blogID,最后我尝试使用下面的代码向 Blogger 发布条目,但此时我收到“HTTP/1.0 400 Bad Request”错误。

request->Clear();
request->Text = Memo3->Lines->Text;  //put entry into request var

IdHTTP2->Request->CustomHeaders->Clear();
IdHTTP2->Request->CustomHeaders->Add("GData-Version=2.0");
IdHTTP2->Request->CustomHeaders->Add("Authorization: GoogleLogin auth="+auth);
IdHTTP2->Request->ContentType = "application/atom+xml";

response->Text = IdHTTP2->Post("https://www.blogger.com/feeds/" + blogID + "/posts/default", request); // I got "HTTP/1.0 400 Bad Request" error right here.

这是我要发布的条目:

<entry xmlns='http://www.w3.org/2005/Atom'>
  <title type='text'>Marriage!</title>
  <content type='xhtml'>
    <div xmlns="http://www.w3.org/1999/xhtml">
      <p>Mr. Darcy has <em>proposed marriage</em> to me!</p>
      <p>He is the last man on earth I would ever desire to marry.</p>
      <p>Whatever shall I do?</p>
    </div>
  </content>
  <category scheme="http://www.blogger.com/atom/ns#" term="marriage" />
  <category scheme="http://www.blogger.com/atom/ns#" term="Mr. Darcy" />
</entry>

我一直在寻找使用 idHTTP 发布它的正确方法,但我一无所获.. :(

有人知道我做错了什么吗?

顺便说一句,我使用的是 CodeGear Delphi/C++Builder 2009,而 Indy 的版本是 10。

非常感谢任何帮助。 谢谢!

【问题讨论】:

  • 乍一看没有发现问题,您可以尝试确保 Auth 令牌中没有多余的空格。我遭受了 400 秒的困扰,直到我意识到我在标头中的 Auth 令牌末尾增加了一个额外的空间。

标签: post c++builder indy blogger idhttp


【解决方案1】:

我发现了如何让它工作。

我删除了行

 IdHTTP2->Request->CustomHeaders->Add("GData-Version=2.0");

然后我换了

 IdHTTP2->Request->CustomHeaders->Add("Authorization: GoogleLogin auth="+auth);

通过

 IdHTTP2->Request->CustomHeaders->Values["Authorization"] = "GoogleLogin auth="+auth;

发件人:https://forums.embarcadero.com/message.jspa?messageID=252770

【讨论】:

    猜你喜欢
    • 2012-02-19
    • 1970-01-01
    • 2015-05-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-01-14
    相关资源
    最近更新 更多