标签: http-get

如何打印httprequest请求的内容?

我有一个涉及httprequest的错误,有时会发生这种错误,因此我想在发生这种情况时记录HttpGet和HttpPost请求的内容.

所以,让我们说,我创建像这样的HttpGet:

HttpGet g = new HttpGet();
g.setURI(new URI("http://www.google.com"));
g.setHeader("test", "hell yeah");
Run Code Online (Sandbox Code Playgroud)

这是我想要的字符串表示:

GET / HTTP/1.1
Host: www.google.com
test: hell yeah
Run Code Online (Sandbox Code Playgroud)

有了post请求,我还想获得内容字符串.

在java for android中最简单的方法是什么?

java android http-get http-post

31
推荐指数
2
解决办法
9万
查看次数

如何通过OkHttp将查询参数添加到HTTP GET请求?

我使用的是最新的okhttp版本:okhttp-2.3.0.jar

如何在java中的okhttp中向GET请求添加查询参数?

我发现了一个关于android 的相关问题,但这里没有答案!

java http-get query-parameters okhttp

31
推荐指数
5
解决办法
5万
查看次数

通过POST请求使用GET请求有什么好处?

我过去的几个ajax应用程序都使用了GET请求,但现在我开始使用POST请求了.POST请求似乎稍微更安全,绝对更友好/漂亮.因此,我想知道为什么我应该使用GET请求.

ajax protocols http http-get http-post

29
推荐指数
6
解决办法
2万
查看次数

如何使用jQuery"load"来执行带有额外参数的GET请求?

我正在阅读jQuery加载文档,它提到我可以通过传入额外的参数作为字符串来使用load来执行GET请求.我的参数作为键/值对的当前代码是:

$("#output").load(
    "server_output.html",
    {
        year: 2009,
        country: "Canada"
    }
);
Run Code Online (Sandbox Code Playgroud)

以上工作正常,但这是一个帖子请求.如何在仍然使用时修改上述内容以执行GET请求load

parameters jquery load http-get

29
推荐指数
2
解决办法
3万
查看次数

PHP cURL GET请求和请求的正文

我正在尝试使用cURL来获取这样的GET请求:

function connect($id_user){
    $ch = curl_init();
    $headers = array(
    'Accept: application/json',
    'Content-Type: application/json',

    );
    curl_setopt($ch, CURLOPT_URL, $this->service_url.'user/'.$id_user);
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
    curl_setopt($ch, CURLOPT_HEADER, 0);
    $body = '{}';

    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET"); 
    curl_setopt($ch, CURLOPT_POSTFIELDS,$body);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

    // Timeout in seconds
    curl_setopt($ch, CURLOPT_TIMEOUT, 30);

    $authToken = curl_exec($ch);

    return $authToken;
}
Run Code Online (Sandbox Code Playgroud)

当你看到我想传递$ body作为请求的正文,但我不知道它是否正确而我实际上无法调试,你知道是否有权使用 curl_setopt($ch, CURLOPT_POSTFIELDS,$body);GET请求吗?

因为这个enteire代码与POST完美配合,现在我正在尝试将此更改为GET,如您所见

php curl http-get

28
推荐指数
3
解决办法
14万
查看次数

如何在WebClient请求中使用动词GET?

我如何更改WebClient请求的动词?它似乎只允许/默认POST,即使在DownloadString的情况下.

        try
        {
            WebClient client = new WebClient();               
            client.QueryString.Add("apiKey", TRANSCODE_KEY);
            client.QueryString.Add("taskId", taskId);
            string response = client.DownloadString(TRANSCODE_URI + "task");                
            result = JsonConvert.DeserializeObject<Dictionary<string, dynamic>>(response);
        }
        catch (Exception ex )
        {
            result = null;
            error = ex.Message + " " + ex.InnerException;
        }
Run Code Online (Sandbox Code Playgroud)

而Fiddler说:

POST http://someservice?apikey=20130701-234126753-X7384&taskId=20130701-234126753-258877330210884 HTTP/1.1
Content-Length: 0
Run Code Online (Sandbox Code Playgroud)

c# webclient http-get

28
推荐指数
1
解决办法
8万
查看次数

angularJS中的同步http调用

我有以下场景,我需要来自特定网址的数据.我写了一个带参数'url'的函数.在函数内部,我有$ http.get方法,它调用url.数据将返回到调用函数

var getData = function (url) {
    var data = "";

    $http.get(url)
        .success( function(response, status, headers, config) {
             data = response;
        })
        .error(function(errResp) {
             console.log("error fetching url");
        });
    return data;
}
Run Code Online (Sandbox Code Playgroud)

问题如下,$ http.get是异步的,在获取响应之前,函数返回.因此,调用函数将数据作为空字符串获取.在从URL中提取数据之前,如何强制函数不返回?

http http-get angularjs

28
推荐指数
3
解决办法
7万
查看次数

REST API:使用正文获取请求

我想实现一个REST API,并且在我的GET请求上需要一个正文.(如下所述:带请求主体的HTTP GET)

是否有http客户端无法发送带有GET请求的正文?Fiddler能够做到这一点,虽然消息框是红色的.

.net rest http-get asp.net-web-api frombodyattribute

22
推荐指数
2
解决办法
4万
查看次数

将int列表传递给HttpGet请求

我的结构与此类似:

[HttpGet]
public HttpResponseMessage GetValuesForList(List<int> listOfIds)
{
    /* create model */        

    foreach(var id in listOfIds)
        model.Add(GetValueForId(id)

    /* create response for model */
    return response;
}
Run Code Online (Sandbox Code Playgroud)

但是,当我对该方法执行Get请求时:

{{domain}}/Controller/GetValuesForList?listOfIds=1&listOfIds=2
Run Code Online (Sandbox Code Playgroud)

调试时声明listOfIds为null ,我收到错误.在我们的控制器中,我们有许多公共HttpGet方法可以正常工作,并且当将参数更改为单个int时,它可以工作.我已经尝试将参数类型更改为int[]IEnumerable<int>,但没有更改.

但是,当将调用更改为HttpPost并将列表作为x-www-form-urlencoded值传递时,该方法可行.

是否可以将列表传递给Get方法,还是必须使用Post?因为它实际上不是post方法(因为它返回值的JSON模型,并且没有任何内容保存到服务器).

c# rest web-services get http-get

22
推荐指数
2
解决办法
3万
查看次数

使用grequests向sourceforge发出数千个请求,获取"使用url超出最大重试次数"

我对这一切都很陌生; 我需要获得数千个sourceforge项目的数据,以便我写一篇论文.数据全部以json格式免费提供,网址为http://sourceforge.net/api/project/name/[project name]/json.我有几千个URL的列表,我使用以下代码.

import grequests
rs = (grequests.get(u) for u in ulist)
answers = grequests.map(rs)
Run Code Online (Sandbox Code Playgroud)

使用此代码,我能够获得我喜欢的任何200个左右项目的数据,即rs = (grequests.get(u) for u in ulist[0:199])工作,但是一旦我查看,所有尝试都会得到满足

ConnectionError: HTTPConnectionPool(host='sourceforge.net', port=80): Max retries exceeded with url: /api/project/name/p2p-fs/json (Caused by <class 'socket.gaierror'>: [Errno 8] nodename nor servname provided, or not known)
<Greenlet at 0x109b790f0: <bound method AsyncRequest.send of <grequests.AsyncRequest object at 0x10999ef50>>(stream=False)> failed with ConnectionError
Run Code Online (Sandbox Code Playgroud)

在我退出python之前,我无法再提出任何请求,但是一旦我重新启动python,我就可以再发出200个请求.

我尝试过使用grequests.map(rs,size=200)但似乎什么也没做.

python http-get grequests

22
推荐指数
1
解决办法
1万
查看次数