Tag: http post

如何编写PHP代码来执行两个函数

我有这个PHP脚本(用于Docker远程API),我用它来“远程”停止一个容器: <?php $cid = trim(file_get_contents('cid')); echo "$cid\n"; function httpPost($url) { $ch = curl_init(); curl_setopt($ch,CURLOPT_URL,$url); curl_setopt($ch,CURLOPT_RETURNTRANSFER,true); curl_setopt($ch,CURLOPT_POST, true); $output=curl_exec($ch); curl_close($ch); return $output; } $url = "http://172.17.0.1:2375/containers/$cid/stop?t=5"; echo "$url\n"; echo httpPost($url) ?> 有用! 但我想要这段代码“停止” 两个docker集装箱,而不是只有一个。 我在想这样的事情: $cid = trim(file_get_contents('cid')); $pid = trim(file_get_contents('pid')); 那么代码的其余部分是怎么样的,这样我们就可以停止这两个呢?

Apache httpcomponent返回java.net.UnknownHostException:名称或服务未知

我试图使用Apache Httpcomponents 4.5.1在Instagram上进行oauthlogin,但是无法成功获取访问令牌。 我很确定这是库本身的问题,因为如果我curl,我会得到我想要的结果。 所以,我尝试了几种不同的方式来完成后调用,但是他们都给了我相同的结果,所以我只是发布我find的最优雅的方式是使用fluent-hc库: @Value("${instagram.client.id}") private String clientID; @Value("${instagram.client.secret}") private String clientSecret; @Value("${instagram.redirect.uri}") private String redirectURI; private static final String INSTAGRAM_ACCESS_TOKEN_URL = "https://api.instagram.com/oauth/access_token"; private Content requestAccessToken(String code, UserType userType) throws IOException { // String authorization_header_string = URLEncoder.encode(clientID + ":" + clientSecret, "UTF-8"); return Request.Post(INSTAGRAM_ACCESS_TOKEN_URL) .bodyForm(Form.form() .add("client_id", clientID) .add("client_secret", clientSecret) .add("grant_type", "authorization_code") .add("redirect_uri", redirectURI + […]

带有URL参数的PHP echo语句

我在PHP中写了一个小脚本来发送POST请求到Web服务器: <?php $cid = file_get_contents('cid'); function httpPost($url) { $ch = curl_init(); curl_setopt($ch,CURLOPT_URL,$url); curl_setopt($ch,CURLOPT_RETURNTRANSFER,true); curl_setopt($ch,CURLOPT_POST, true); $output=curl_exec($ch); curl_close($ch); return $output; } echo httpPost("http://172.17.0.1:2375/containers/$cid/stop?t=5"); ?> 是的,这是Docker。 我在Docker中使用远程API ,这个脚本的一小部分工作! 但是,URL末尾的?t = 5会被忽略。 我猜这跟那个有关系? 。 如何正确格式化此url,以使t = 5正常工作? (到目前为止,我尝试了1,001种方法,用引号和双引号,没有运气,花了4个多小时,我认为stackoverflow可以帮忙?) 谢谢… 注意:“cid”只是硬盘上的一个文件,用于存储容器ID。 所以我从文件中检索容器ID,并将其传递给URL(这部分工作,无论如何)。 完整的URL是由我写的,即不parsing。