doufei2328 2014-07-27 16:32
浏览 68
已采纳

使用JSON通过http搜索查询

I am sending an API request and want to submit a search term inside the URL:

$query="My Query";
$query_encode= urlencode($query);

$url_json="API_URL".$query_encode
$json = file_get_contents($url_json);

What I want to do is that "My Query" should contain a more complex term like:

"word1 word2" (word3 OR word4) AND word5

My problem is that I want to get the results from the API (database) that match excactly "word1 word2" so I need to somehow send the quoatation marks via http.

Does someone has an idea how I need to set up the content of My Query including the required quotation marks to send a query with the phrase, not just the words

$query="My Query";
  • 写回答

2条回答 默认 最新

  • dplbf4340 2014-07-27 16:45
    关注

    if you want to send the quotes then include it in your query.

    you set a string value inside quotes in PHP. so what you have right now are not additional quotes that you want to send along in the request but the quotes that will be parsed and removed by PHP.

    you should do something like:

    $query='"My Query"';
    

    this will result in something like %22My+Query%22

    urldecode this later to get back "My Query" as string value.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?
  • ¥15 乘性高斯噪声在深度学习网络中的应用
  • ¥15 运筹学排序问题中的在线排序
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥30 求一段fortran代码用IVF编译运行的结果
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛