dsf45346 2017-12-28 23:46
浏览 108

如何从wordpress中的cURL请求中提取信息

This is the header: GFC-X-PORTER-PIPE: wZ5u8QgsCsTKR2Wz

Content-Type: application/json

So when you do a get using curl(like below): curl -XGET -H "GFC-X-PORTER-PIPE: wZ5u8QgsCsTKR2Wz" -H "Content-Type: application/json" "https://mywebsite.com/employeestatus?key=John.Doe|John%20Doe"

RESULT: {"name":"John Doe","request_header":{"Source-IP":"50.200.140.2"},"status":"out","update_date":"2017-12-13 08:54:04","username":"John.Doe","key":"John.Doe|John Doe"}

If you look at the result, you will see the status “OUT” (in red font) and that will change as there is a script that runs to update that status. That status needs to be underneath the employee info (except the executives) on this link: https://www.mywebsite.com/contact-us/addison/, https://www.mywebsite.com/contact-us/chicago/, and https://www.mywebsite.com/contact-us/hammond/ and you match their key(in yellow highlight) to the user in the contact-us page of the website.

It should show as “I am IN” and “I am OUT” underneath each user. The “IN” and “OUT” word will come from the database and the “I am” is hardcoded.

  • 写回答

1条回答 默认 最新

  • doucong1992 2017-12-29 04:32
    关注

    You can use WordPress' built in WP_Http class to make HTTP requests like so:

    <?php
    $client = new WP_Http();
    
    $request = $client->request( 'https://mywebsite.com/employeestatus', array(
        'headers' => array(
            'GFC-X-PORTER-PIPE: wZ5u8QgsCsTKR2Wz',
            'Content-Type: application/json',
        ),
        'body'    => array(
            'key' => 'John.Doe|John Doe',
        ),
    ) );
    
    $result = $request['body']; // This is your request output.
    

    Then you can do whatever you want with your $result, you'll probably want to json_decode() it first.

    评论

报告相同问题?

悬赏问题

  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?