记一次php curl给java提交数据失败的经历


$url = 'http://www.test.com';
$data = array(
  'name' => 'test',
  'age' => 123,
$curl = curl_init (); // 启动一个CURL会话
curl_setopt ( $curl, CURLOPT_URL, $url ); // 要访问的地址
curl_setopt ( $curl, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt ( $curl, CURLOPT_POSTFIELDS, $data); // Post提交的数据包
$result = curl_exec ( $curl ); // 执行操作
curl_close ( $curl ); 


  • CURLOPT_POSTFIELDS 这个参数字段数据为一个数组时,Content-Type头将会被设置成multipart/form-data(数据格式);
  • 而这个参数字符串类似’para1=val1&para2=val2&…’时,Content-Type头将会被设置成application/x-www-form-urlencoded(表单格式),就像表单提交的一样。

对方接收的Content-Type为application/x-www-form-urlencoded(表单格式),而现在PHP curl post提交数据时Content-Type为multipart/form-data(数据格式)。这才导致对方无法通过POST来接收数据。现在只需要把代码中

curl_setopt ( $curl, CURLOPT_POSTFIELDS, $data);
curl_setopt ( $curl, CURLOPT_POSTFIELDS, http_build_query($data));





$ch = curl_init();
$data = array('name' => 'Foo', 'file' => '@/home/user/test.png');
curl_setopt($ch, CURLOPT_URL, 'http://localhost/upload.php');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);

13,699 Responses

  1. Pyridium Cheap Cod Accepted. Order Online Pyridium Discount Without Dr Approval. Want To Buy Generic Pyridium Website Cash Delivery Overseas Cialis Im Flugzeug Mitnehmen Viagra 100mg Preis Apotheke cialis online Amoxicillin Absorbtion Amount Propecia 8 Months Medicine Alternativa Al Viagra

  2. Combien Coute Le Cialis Priligy Se Vende En Mexico Cialis Generika 20mg Bestellen Expired Amoxicillin Cialis Belgique Allemagne

  3. Where Can I Buy Online Cheap Cialis Cephalexin Vaginal Bacterial Infection Viagra Generico Comprar cialis 5mg Isotretinoin Where To Purchase Clomid Buy India What Is Keflex Prescription

  4. I would like to voice my respect for your generosity supporting men and women that absolutely need assistance with this area of interest. Your personal commitment to passing the message along ended up being remarkably useful and have all the time allowed employees like me to arrive at their aims. Your amazing important report means so much to me and even more to my office colleagues. Best wishes; from everyone of us.

  5. I simply wanted to appreciate you yet again. I do not know the things I would have handled without the actual recommendations shared by you directly on such concern. It actually was a real frightening condition in my position, but being able to view a well-written avenue you handled the issue made me to weep for joy. I am grateful for your support and as well , wish you are aware of a powerful job you’re doing educating other individuals via your web site. I am sure you have never got to know any of us.

  6. I’ll right away take hold of your rss feed as I caan not in finding your e-mail subscription link or newsletter service.
    Do you’ve any? Pleease permit me understand so that I could subscribe.


  7. You can certainly see your skills in the article you write.
    The world hopes for more passionate writers like you who are not afraid
    to say how they believe. All the time go after your heart.

  8. Thanks for any other magnificent post. The place else could anyone
    get that type of information in such a perfect means of writing?

    I have a presentation next week, and I’m at the look for such

  9. I really like your blog.. very nice colors & theme. Did you design this website yourself or did you hire someone to do it for you?
    Plz answer back as I’m looking to create my own blog and would like to find out
    where u got this from. many thanks

  10. Hey there I am so happy I found your website, I really found you by accident, while I was looking on Askjeeve for something else, Anyhow
    I am here now and would just like to say thank you for a tremendous post and a all round enjoyable blog
    (I also love the theme/design), I don’t have time to read through it all at
    the moment but I have book-marked it and also added
    your RSS feeds, so when I have time I will be back to read
    more, Please do keep up the awesome job.

  11. Thanks , I’ve recently been searching for info about this subject
    for ages and yours is the greatest I’ve came upon so far.
    But, what concerning the conclusion? Are you certain about
    the supply?

  12. May I just say what a relief to find an individual who really understands what they’re discussing online. You actually know how to bring an issue to light and make it important. More and more people have to look at this and understand this side of your story. It’s surprising you’re not more popular since you definitely possess the gift.

    https://www.manumanu.com – manu manumanu

  13. I believe everything said was very reasonable. But, what
    about this? suppose you were to create a killer headline?
    I am not saying your information isn’t solid.,
    but suppose you added a headline to possibly get folk’s attention? I mean 记一次php
    curl给java提交数据失败的经历 | Lyy's blog is a little plain.
    You ought to peek at Yahoo’s home page and watch how they create news titles to grab people to open the links.
    You might add a related video or a picture or two
    to grab readers excited about everything’ve written. In my opinion, it would bring
    your blog a little livelier.

  14. Do you have a spam problem on this website; I also am a blogger,
    and I was curious about your situation; we have created some nice
    practices and we are looking to trade methods with other folks,
    why not shoot me an email if interested.

  15. It is the best time to make a few plans for the future and it is time to
    be happy. I have read this publish and if I may I
    want to recommend you few fascinating things or advice.
    Perhaps you can write subsequent articles regarding this article.
    I want to read more issues approximately it!

  16. I do not even know how I ended up right here, however I assumed this
    submit used to be good. I do not recognize who you’re but
    certainly you are going to a well-known blogger if you aren’t already.

  17. hello!,I really like your writing very so much! share
    we keep in touch more about your post on AOL?
    I require a specialist in this area to solve my problem.
    May be that’s you! Looking ahead to see you.

  18. It is the best time to make some plans for the future and it is time to be happy.

    I’ve read this post and if I could I desire to suggest you few interesting things or
    suggestions. Maybe you can write next articles referring
    to this article. I want to read even more things about it!

  19. I’ll right away seize your rss as I can’t find your
    email subscription hyperlink or e-newsletter service.
    Do you have any? Please let me know so that I may just subscribe.

  20. We’re a gaggle of volunteers and opening a new scheme in our community.
    Your site offered us with valuable information to work on. You have performed a formidable activity and
    our entire community can be thankful to you.

  21. You have made some really good points there. I looked on the internet to
    find out more about the issue and found most people will go along with your views on this web site.

  22. I’m impressed, I must say. Seldom do I encounter a blog that’s equally educative and interesting,
    and without a doubt, you’ve hit the nail on the head.
    The issue is something too few men and women are speaking intelligently
    about. I’m very happy that I stumbled across this during
    my search for something regarding this.

  23. You made some good points there. I checked on the net to find out more about the issue and found
    most people will go along with your views on this site.

  24. My spouse and I stumbled over here different page and thought I may as well check things out.
    I like what I see so i am just following you. Look forward to looking
    over your web page repeatedly.

  25. Your style is really unique compared to other people
    I have read stuff from. Many thanks for posting when you have the
    opportunity, Guess I’ll just bookmark this blog.

  26. When someone writes an paragraph he/she retains the image of a user in his/her brain that how a user can know it.
    Thus that’s why this piece of writing is perfect. Thanks!

  27. Hello I am so grateful I found your blog page, I really found you by mistake, while I
    was researching on Askjeeve for something else, Anyways I am here now and would just like to say many thanks for a marvelous post and a all round entertaining blog (I also
    love the theme/design), I don’t have time to look over it all at the moment but I have saved it and also included your RSS feeds, so when I have time
    I will be back to read a great deal more, Please do keep up
    the awesome job.