<i id='Ofy3i'><tr id='Ofy3i'><dt id='Ofy3i'><q id='Ofy3i'><span id='Ofy3i'><b id='Ofy3i'><form id='Ofy3i'><ins id='Ofy3i'></ins><ul id='Ofy3i'></ul><sub id='Ofy3i'></sub></form><legend id='Ofy3i'></legend><bdo id='Ofy3i'><pre id='Ofy3i'><center id='Ofy3i'></center></pre></bdo></b><th id='Ofy3i'></th></span></q></dt></tr></i><div id='Ofy3i'><tfoot id='Ofy3i'></tfoot><dl id='Ofy3i'><fieldset id='Ofy3i'></fieldset></dl></div>

    1. <small id='Ofy3i'></small><noframes id='Ofy3i'>

      <legend id='Ofy3i'><style id='Ofy3i'><dir id='Ofy3i'><q id='Ofy3i'></q></dir></style></legend><tfoot id='Ofy3i'></tfoot>
        <bdo id='Ofy3i'></bdo><ul id='Ofy3i'></ul>
      1. 通过 curl 发送 xml 和 headers

        时间:2024-08-22

                <i id='nm51p'><tr id='nm51p'><dt id='nm51p'><q id='nm51p'><span id='nm51p'><b id='nm51p'><form id='nm51p'><ins id='nm51p'></ins><ul id='nm51p'></ul><sub id='nm51p'></sub></form><legend id='nm51p'></legend><bdo id='nm51p'><pre id='nm51p'><center id='nm51p'></center></pre></bdo></b><th id='nm51p'></th></span></q></dt></tr></i><div id='nm51p'><tfoot id='nm51p'></tfoot><dl id='nm51p'><fieldset id='nm51p'></fieldset></dl></div>
                <legend id='nm51p'><style id='nm51p'><dir id='nm51p'><q id='nm51p'></q></dir></style></legend>

                <small id='nm51p'></small><noframes id='nm51p'>

                  <tbody id='nm51p'></tbody>
                <tfoot id='nm51p'></tfoot>
                  <bdo id='nm51p'></bdo><ul id='nm51p'></ul>
                • 本文介绍了通过 curl 发送 xml 和 headers的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  想知道如何通过 php 在 curl 会话中设置所有这些数据:

                  wondering how I can set all this data in a curl session, via php:

                  POST /feeds/api/users/default/uploads HTTP/1.1
                  Host: uploads.gdata.youtube.com
                  Authorization: AuthSub token="DXAA...sdb8"
                  GData-Version: 2
                  X-GData-Key: key=adf15ee97731bca89da876c...a8dc
                  Slug: video-test.mp4
                  Content-Type: multipart/related; boundary="f93dcbA3"
                  Content-Length: 1941255
                  Connection: close
                  
                  --f93dcbA3
                  Content-Type: application/atom+xml; charset=UTF-8
                  
                  <?xml version="1.0"?>
                  <entry xmlns="http://www.w3.org/2005/Atom"
                    xmlns:media="http://search.yahoo.com/mrss/"
                    xmlns:yt="http://gdata.youtube.com/schemas/2007">
                    <media:group>
                      <media:title type="plain">Bad Wedding Toast</media:title>
                      <media:description type="plain">
                        I gave a bad toast at my friend's wedding.
                      </media:description>
                      <media:category
                        scheme="http://gdata.youtube.com/schemas/2007/categories.cat">People
                      </media:category>
                      <media:keywords>toast, wedding</media:keywords>
                    </media:group>
                  </entry>
                  --f93dcbA3
                  Content-Type: video/mp4
                  Content-Transfer-Encoding: binary
                  
                  <Binary File Data>
                  --f93dcbA3--
                  

                  我不明白为什么有一些标题,然后 --f93dcbA3 更多标题(边界是什么?),一些 xml(为什么在这里?),更多标题和文件内容.

                  I don't understand why have some headers, then the --f93dcbA3 more headers (what's the boundary?), some xml (why here ?), more headers and the content of a file.

                  我知道如何在没有 xml 部分和边界"的情况下发出请求.

                  I know how to make the request without the xml part and the 'boundary'.

                  任何帮助将不胜感激:D

                  Any help will be appreciated :D

                  推荐答案

                  边界是必需的,因为form enctype是multipart/form-data,而不是在这种情况下multipart/related.边界是一个唯一的字符串,不能出现在请求的其他任何地方,它用于将每个元素与表单分开,无论是文本输入的值,还是文件上传的值.每个边界都有自己的内容类型.

                  The boundary is required because the form enctype is multipart/form-data, rather in this case multipart/related. The boundary is a unique string that cannot appear anywhere else in the request, and it is used to separate each element from the form, whether it is the value of a text input, or a file upload. Each boundary has its own content-type.

                  Curl 无法为您执行 multipart/related,因此您需要使用解决方法,请参阅 这条消息来自 curl 邮件列表以获取建议.基本上,您必须自己构建大部分消息.

                  Curl cannot do multipart/related for you, so you will need to use a workaround, see this message from the curl mailing list for suggestions. Basically, you will have to construct most of the message yourself.

                  注意,最后一个边界在末尾多了一个--.

                  Note, the last boundary has an additional -- at the end.

                  此代码有望帮助您入门:

                  This code should hopefully help get you started:

                  <?php
                  
                  $url       = 'http://uploads.gdata.youtube.com/feeds/api/users/default/uploads';
                  $authToken = 'DXAA...sdb8'; // token you got from google auth
                  $boundary  = uniqid();      // generate uniqe boundary
                  $headers   = array("Content-Type: multipart/related; boundary="$boundary"",
                                     "Authorization: AuthSub token="$authToken"",
                                     'GData-Version: 2',
                                     'X-GData-Key: key=adf15....a8dc',
                                     'Slug: video-test.mp4');
                  
                  $postData  = "--$boundary
                  "
                              ."Content-Type: application/atom+xml; charset=UTF-8
                  
                  "
                              .$xmlString . "
                  "  // this is the xml atom data
                              ."--$boundary
                  "
                              ."Content-Type: video/mp4
                  "
                              ."Content-Transfer-Encoding: binary
                  
                  "
                              .$videoData . "
                  "  // this is the content of the mp4
                              ."--$boundary--";
                  
                  
                  $ch  = curl_init($url);
                  curl_setopt($ch, CURLOPT_POST, 1);
                  curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
                  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
                  curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
                  curl_setopt($ch, CURLOPT_HEADER, 0);
                  curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
                  
                  $response = curl_exec($ch);
                  curl_close($ch);
                  

                  希望对您有所帮助.

                  这篇关于通过 curl 发送 xml 和 headers的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                        <tbody id='bNMIc'></tbody>
                    • <tfoot id='bNMIc'></tfoot>

                      <i id='bNMIc'><tr id='bNMIc'><dt id='bNMIc'><q id='bNMIc'><span id='bNMIc'><b id='bNMIc'><form id='bNMIc'><ins id='bNMIc'></ins><ul id='bNMIc'></ul><sub id='bNMIc'></sub></form><legend id='bNMIc'></legend><bdo id='bNMIc'><pre id='bNMIc'><center id='bNMIc'></center></pre></bdo></b><th id='bNMIc'></th></span></q></dt></tr></i><div id='bNMIc'><tfoot id='bNMIc'></tfoot><dl id='bNMIc'><fieldset id='bNMIc'></fieldset></dl></div>
                      • <bdo id='bNMIc'></bdo><ul id='bNMIc'></ul>
                        <legend id='bNMIc'><style id='bNMIc'><dir id='bNMIc'><q id='bNMIc'></q></dir></style></legend>

                        <small id='bNMIc'></small><noframes id='bNMIc'>