doufan6033 2015-11-12 17:39
浏览 20
已采纳

在正文中引用HTML标记

I need to send HTML components in the BODY of a POST throught Guzzle.

These are the HTML TAGS:

$strData = "<p style='background:url(/clear.png?org_id=1snn5n9w&amp;session_id=123456789&amp;m=1)'>< / p >
<img src='/clear.png?org_id=1snn5n9w&amp;session_id=123456789&amp;m=2' alt=''>";

My Guzzle code is:

$client = new GuzzleHttp\Client(['base_uri' => 'https://thirdURL.com/Test.htm', 'http_errors'=>true]);

$resH = $client->post('https://thirdURL . com/Test.htm',[
            'form_params' =>['body' => $strData]]);

Is this the correct way to send this kind of objects via Guzzle? Thanks for your help.

Regards.

  • 写回答

1条回答 默认 最新

  • doumeng4400 2015-11-12 18:13
    关注

    If you are not trying to send data as a query parameter (think of a form submission) then there is no need to use "form_params".

    If all you want is the body to contain the desired html string you should be able to do the following:

    $resH = $client->post('https://thirdURL.com/Test.htm',[
        'body' => $strData,
    ]);
    

    More information can be obtained by reading through the Guzzle Documentation on Post Requests

    The 'form_params' request option is essentially a short-cut way of performing:

    $response = $client->post($uri, [
        'headers' => [
            'Content-Type' => 'application/x-www-form-urlencoded',
        ],
        'body' => http_build_query($form_params_array),
    ])
    

    So in essence, for your particular use case the body of your http request would contain the post query and the html content.

    The answer to your question of 'will it work?', is simply (and albeit unhelpful) -- "I don't know". At the end of the day, it all depends on what the server will accept.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 用hfss做微带贴片阵列天线的时候分析设置有问题
  • ¥15 基于52单片机的酒精浓度检测系统加继电器和sim800
  • ¥50 我撰写的python爬虫爬不了 要爬的网址有反爬机制
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥120 计算机网络的新校区组网设计
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 海浪数据 南海地区海况数据,波浪数据
  • ¥20 软件测试决策法疑问求解答