2009-09-18 46 views
1

这让我头疼几个小时,我尝试使用curl与我的Twitter帐户发布图像到twitpic。如何发布包含符号的多部分/表单数据

 
curl -F "username=myusername" -F "password=='hwsh[g" -F "message=test twitpic" -F [email protected]/dos/smallapps2/smallapps/tiny-delicious/snapshot/test.png http://twitpic.com/api/uploadAndPost 

它送花儿给人返回

<?xml version="1.0" encoding="UTF-8"?> 
    <rsp stat="fail"> 
     <err code="1001" msg="Invalid twitter username or password" /> 
    </rsp> 

但是,当我改变Twitter的密码,以简单的文字(不包含 “=”, “ - ”, “[”) 它确定

<?xml version="1.0" encoding="UTF-8"?> 
<rsp status="ok"> 
<statusid>4084106555</statusid> 
<userid>33348202</userid> 
<mediaid>56qrz</mediaid> 
<mediaurl>http://twitpic.com/i6qwg</mediaurl> 
</rsp> 

我的问题是如何使用包含任何字符的强密码来做这件事。 请提示。 谢谢。

+2

尝试urlencode它。 – Eimantas 2009-09-18 18:22:11

回答

0

我试着运行您的示例,使用完全相同的密码(在测试帐户上),并且没有任何问题上传我的示例图像。我甚至通过pcap查看,以确保编码正确完成。

-desktop:~/Dropbox$ curl -vv -F "username=********" -F "password=='hwsh[g" -F "message=test twitpic" -F [email protected]/code_Quality_Measurement_wtfm.jpg http://twitpic.com/api/uploadAndPost 
* About to connect() to twitpic.com port 80 (#0) 
* Trying 174.36.58.233... connected 
* Connected to twitpic.com (174.36.58.233) port 80 (#0) 
> POST /api/uploadAndPost HTTP/1.1 
> User-Agent: curl/7.19.5 (i486-pc-linux-gnu) libcurl/7.19.5 OpenSSL/0.9.8g zlib/1.2.3.3 libidn/1.15 
> Host: twitpic.com 
> Accept: */* 
> Content-Length: 46066 
> Expect: 100-continue 
> Content-Type: multipart/form-data; boundary=----------------------------50b761e49108 
> 
< HTTP/1.1 100 Continue 
< HTTP/1.1 200 OK 
< Server: nginx/0.6.35 
< Date: Thu, 03 Dec 2009 19:06:38 GMT 
< Content-Type: application/xml 
< Connection: keep-alive 
< X-Powered-By: PHP/5.2.9 
< Content-Length: 196 
< 
<?xml version="1.0" encoding="UTF-8"?> 
<rsp status="ok"> 
<statusid>6311967029</statusid> 
<userid>**********</userid> 
<mediaid>rzu6c</mediaid> 
<mediaurl>http://twitpic.com/rzu6c</mediaurl> 
* Connection #0 to host twitpic.com left intact 
* Closing connection #0 
</rsp> 

你在用什么壳牌?根据您在密码中使用什么“特殊”字符,您可能需要以不同的方式将它们转义出来以防止扩展shell等等。任何时候在命令行中使用双引号时,必须处理变量扩展特别是如果您的密码包含美元($)。最好在密码字段周围使用单引号,并明确地转义密码中的任何单引号:

-F 'password==\'hwsh[g' 
相关问题