首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >通过idHTTP向博主发帖

通过idHTTP向博主发帖
EN

Stack Overflow用户
提问于 2011-08-17 18:09:50
回答 1查看 1.8K关注 0票数 0

我正试图使用idHTTP组件向博主发帖,但是,我得到了“HTTP/1.0400BAD请求”错误。

首先,我得到了Auth代码,通过使用下面的代码,它可以很好地工作:

代码语言:javascript
复制
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,但此时我得到了“HTTP1.0400BAD请求”错误。

代码语言:javascript
复制
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.

这是我要发布的条目:

代码语言:javascript
复制
<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。

任何帮助都是非常感谢的。谢谢!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-08-19 19:06:39

我找到了让它工作的方法。

我删除了线

代码语言:javascript
复制
 IdHTTP2->Request->CustomHeaders->Add("GData-Version=2.0");

然后我换了

代码语言:javascript
复制
 IdHTTP2->Request->CustomHeaders->Add("Authorization: GoogleLogin auth="+auth);

通过

代码语言:javascript
复制
 IdHTTP2->Request->CustomHeaders->Values["Authorization"] = "GoogleLogin auth="+auth;

来自:https://forums.embarcadero.com/message.jspa?messageID=252770

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/7097425

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档