通过idHTTP发布到博客
问题描述:
我试图发布到使用idHTTP组件的Blogger,但是,我收到“HTTP/1.0 400错误请求”错误。通过idHTTP发布到博客
首先,我得到了验证码,这完全符合使用下面的代码工作:
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"] = "[email protected]";
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最后我尝试使用下面的代码发布到博客条目,但这一刻我得到“HTTP/1.0 400错误请求”错误。
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德尔福/ C + + Builder 2009 2009年和Indy的版本是10.
任何帮助,非常感谢。 谢谢!
答
我发现如何让它工作。
我删除线
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
没有看到第一眼的问题,你可以尝试确保你'在Auth令牌中没有多余的空格。我在很长一段时间里遭受了400多年的困扰,直到我意识到我在标题中的Auth令牌末尾增加了一个额外的空间。 –