PHP failed to send Weibo

Source: Internet
Author: User
Tags chop
PHP Micro-Blog Windows

Title, the packets are crawled with fiddler.
POST http://weibo.com/aj/mblog/add?_wv=5&__rnd=1374042943531 http/1.1
Host:weibo.com
Connection:keep-alive
Content-length:85
Origin:http://weibo.com
X-requested-with:xmlhttprequest
user-agent:mozilla/5.0 (Windows NT 5.1) applewebkit/537.17 (khtml, like Gecko) chrome/24.0.1312.57 safari/537.17 SE 2.X M ETASR 1.0
content-type:application/x-www-form-urlencoded
Accept: */*
Referer:http://weibo.com/111690558?topnav=1&wvr=5
Accept-encoding:gzip,deflate,sdch
accept-language:zh-cn,zh;q=0.8
accept-charset:gbk,utf-8;q=0.7,*;q=0.3
cookie:sinaglobal=9465448379050.94.1363149364838; __utma=182865017.444875141.1368123665.1368123665.1368123665.1; __utmz=182865017.1368123665.1.1.utmcsr=weibo.com|utmccn= (referral) |utmcmd=referral|utmcct=/111690558; un=15060958332; wvr=5; Tips_1690464047=1; usrhawb=usrmdins540_129; sue=es%3d507eea8961adc4be8745ced26692cecf%26ev%3dv1%26es2%3d60cde3f363e58640ff977cc494b9b324%26rs0% 3dhocml5t36i5cpm5fjt6zoy8aohoq%252frcttfun3dwvh1vp%252fhztj0d2wiltrp8ftl8afkfeiqhgdz873epbi85zzxqxh% 252fzlfrnq8v3cfxgdwii%252bjuink2unhthidtqeofdz83%252be7tm6z2khuwj1h6yaq5vuirx39if85cauor0ejzg%253d%26rv%3d0; sup=cv%3d1%26bt%3d1374020329%26et%3d1374106729%26d%3dc909%26i%3d9e53%26us%3d1%26vf%3d0%26vt%3d0%26ac%3d2%26st% 3d0%26uid%3d1690464047%26name%3d15060958332%2540sina.cn%26nick%3d15060958332%26fmp%3d%26lcp%3d; Sus=sid-1690464047-1374020329-gz-57e6f-e2b33deb6283a87d733e40d63e8f7ee9; alf=1376127464; ssologinstate=1374020329; usrug=usrmdins1540_23; _s_tentry=login.sina.com.cn; apache=7815071931108.832.1374020351610; ulv=1374020351624:608:64:33:7815071931108.832.1374020351610:1373988030276; uor=,weibo.com,bbs.fzu.edu.cn; sinarot_wb_r_topic=94; Arp_scroll_position=0

Text=test&pic_id=&rank=0&rankid=&_surl=&hottopicid=&location=home&module=stissue &_t=0

Normal send data packet as above

PHP is written in this format as follows

 



The result is

301 Moved Permanently
 
  
  
   

301 Moved Permanently

Nginx


But to copy this packet to fiddler and other tools to send, obviously is successful, is PHP where there is a problem?

Some articles say that the packet post_str the back part should be added \r\n\r\n, I have tried, plus two, plus one, not add, are the failure

PS: I am using PHP under the command line


Reply to discussion (solution)

Maybe it's a cookie question, you put

I have previously written in Ruby a self-brush review of other micro-blog programs, for your reference. Similar to the kind of ad robot on Weibo.
After the run will automatically comment on the latest Weibo address of the designated Weibo, 10 second comments once. Comments finally I added a very long random string to prevent being filtered by Sina.

Operating Environment: ruby1.9+

#! /usr/local/bin/ruby-w#-*-coding:utf-8-*-require ' Net/http ' class auto_comment@ @comment_url = ' http://weibo.com/aj/ comment/add?_wv=5&__rnd=13811801512 ' @ @headers = {' Cookie ' + ' [change here to your cookie] ', ' Referer ' + '/' Weibo.com ', ' user-agent ' = ' mozilla/5.0 ' (Macintosh; Intel Mac OS X 10_8_2) applewebkit/537.22 (khtml, like Gecko) chrome/25.0.1364.172 safari/537.22 ', ' content-type ' = ' AP Plication/x-www-form-urlencoded '}def exec Weibo, Content@weibo = Weibo@content = Contentcheck_new_postendprivatedef Create_salt chars = ("a" ... " Z "). To_a newpass =" "1.upto {|i|  Newpass << Chars[rand (chars.size-1)]} newpassenddef Check_new_posturi = Uri.parse @weiboreq = net::http::get.new Uri.request_uri, @ @headersres = Net::http.start uri.host, uri.port do |http|http.request (req) endmid_list = Res.body.scan (/mid=\\\ "(. *?) \\\ "/) mid = mid_list.first[0].to_scomment Midenddef Comment midpostfields = {: act = ' post ',: mid = = Mid,:forward = > ' 0 ',: isroot = ' 0 ',: Content + @content + "_ Anti-Sina Filter duplicate content random string {" +create_salt+ "}",: type = ' big ',: location = ' Mblog ',: module = > ' bcommlist ',: Tranandcomm = ' 1 ',: _t = ' 0 '}uri = uri.parse @ @comment_urlhttp = net::http.new (uri.host, +) Fiel D = ' Postfields.each do |k, V|field + = "#{k}=#{v}&" Endfield.chop!http.post uri.request_uri, field, @ @headersendend # To comment on the Weibo address Weibo = ' http://weibo.com/u/1777627917 ' content = ' Automatic comment program test ' comment = auto_comment.new# comments once every 10 seconds loop Docomment.exec Weibo, Contentsleep 10end

Maybe it's a cookie question, you put

I have previously written in Ruby a self-brush review of other micro-blog programs, for your reference. Similar to the kind of ad robot on Weibo.
After the run will automatically comment on the latest Weibo address of the designated Weibo, 10 second comments once. Comments finally I added a very long random string to prevent being filtered by Sina.

Operating Environment: ruby1.9+

#! /usr/local/bin/ruby-w#-*-coding:utf-8-*-require ' Net/http ' class auto_comment@ @comment_url = ' http://weibo.com/aj/ comment/add?_wv=5&__rnd=13811801512 ' @ @headers = {' Cookie ' + ' [change here to your cookie] ', ' Referer ' + '/' Weibo.com ', ' user-agent ' = ' mozilla/5.0 ' (Macintosh; Intel Mac OS X 10_8_2) applewebkit/537.22 (khtml, like Gecko) chrome/25.0.1364.172 safari/537.22 ', ' content-type ' = ' AP Plication/x-www-form-urlencoded '}def exec Weibo, Content@weibo = Weibo@content = Contentcheck_new_postendprivatedef Create_salt chars = ("a" ... " Z "). To_a newpass =" "1.upto {|i|  Newpass << Chars[rand (chars.size-1)]} newpassenddef Check_new_posturi = Uri.parse @weiboreq = net::http::get.new Uri.request_uri, @ @headersres = Net::http.start uri.host, uri.port do |http|http.request (req) endmid_list = Res.body.scan (/mid=\\\ "(. *?) \\\ "/) mid = mid_list.first[0].to_scomment Midenddef Comment midpostfields = {: act = ' post ',: mid = = Mid,:forward = > ' 0 ',: isroot = ' 0 ',: Content + @content + "_ Anti-Sina Filter duplicate content random string {" +create_salt+ "}",: type = ' big ',: location = ' Mblog ',: module = > ' bcommlist ',: Tranandcomm = ' 1 ',: _t = ' 0 '}uri = uri.parse @ @comment_urlhttp = net::http.new (uri.host, +) Fiel D = ' Postfields.each do |k, V|field + = "#{k}=#{v}&" Endfield.chop!http.post uri.request_uri, field, @ @headersendend # To comment on the Weibo address Weibo = ' http://weibo.com/u/1777627917 ' content = ' Automatic comment program test ' comment = auto_comment.new# comments once every 10 seconds loop Docomment.exec Weibo, Contentsleep 10end

How do you get the cookie, the Rnd parameter should be synchronized with the time ...?? I removed and found that it is not normal, the cookie should be correct, I send a packet of PHP echo to send with other software can be

__rnd parameters I gave you a definite value. Removal may not be possible, but can give a fixed value.
The cookie I took from Chrome's censorship element.

If you are sure that the cookie is OK, you are sending the HTTP header thin, just like me sending only 4 domains. Because your result is 301, so I still suspect that the part of your cookie verification did not pass.


I also used PHP to write a few operations microblogging, such as automatic tweet, automatic attention to others, etc., but the code is not saved. So I can't send it to you for reference.

__rnd parameters I gave you a definite value. Removal may not be possible, but can give a fixed value.
The cookie I took from Chrome's censorship element.

If you are sure that the cookie is OK, you are sending the HTTP header thin, just like me sending only 4 domains. Because your result is 301, so I still suspect that the part of your cookie verification did not pass.


I also used PHP to write a few operations microblogging, such as automatic tweet, automatic attention to others, etc., but the code is not saved. So I can't send it to you for reference.
Only four of the head or not can still be 301, I do not understand.

Where's $post _str?

$post _header.= "text=test&pic_id=&rank=0&rankid=&_surl=&hottopicid=&location=home& Module=stissue&_t=0 ";
Post data should not be added to the header and should be handled with curl-related parameters

Where's $post _str?

$post _header.= "text=test&pic_id=&rank=0&rankid=&_surl=&hottopicid=&location=home& Module=stissue&_t=0 ";
Post data should not be added to the header and should be handled with curl-related parameters
The content length was found in the test, so I poststr.

The problem is that curl doesn't open the Curl module under the command line.

And the other sites do not have this problem I also want to know exactly what the situation.

Didn't see Connection:close.
I didn't see content-length:nnn.

In general, the length of the post data is stated before Connection:close, and the data body is appended to the body, i.e. after connection:close

Didn't see Connection:close.
I didn't see content-length:nnn.

In general, the length of the post data is stated before Connection:close, and the data body is appended to the body, i.e. after connection:close
That's what the data is like when it's normally sent.
In addition, PHP is the same as normal delivery is keep-alive on the third line

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.