标签: http-post

C#:如何通过WebRequest发布大字符串?

我如何使用POST上传一个大字符串(在我的情况下使用BLOB的XML)而不使用GetResponse获取Timeout?

更改超时有帮助,但这不是一个真正的解决方案.如果服务器确实死亡或POST中断,我必须等待极端大超时.

任何的想法?

HttpWebRequest webRequest = null;
string response = "";
byte[] bytes = Encoding.UTF8.GetBytes(xml);

try
{
    webRequest = (HttpWebRequest)WebRequest.Create("http://" + this.host + ":" + this.port);
    webRequest.ContentType = "application/x-www-form-urlencoded";
    webRequest.Method = "POST";
    webRequest.Timeout = 5000;

    webRequest.ContentLength = bytes.Length;
    using (Stream requeststream = webRequest.GetRequestStream())
    {
        requeststream.Write(bytes, 0, bytes.Length);
        requeststream.Close();
    }

    using (HttpWebResponse webResponse = (HttpWebResponse)webRequest.GetResponse())
    {
        using (StreamReader sr = new StreamReader(webResponse.GetResponseStream()))
        {
            response = sr.ReadToEnd().Trim();
            sr.Close();
        }
        webResponse.Close();
    }
}
catch(Exception ex)
{
    MessageBox.Show(ex.ToString());
}
return response;
Run Code Online (Sandbox Code Playgroud)

c# timeout http-post httpwebrequest

9
推荐指数
1
解决办法
7339
查看次数

如何通过用C编写的cgi-bin程序检索表单"POST"数据

我正在尝试使用用C编写的程序从html表单中检索POST数据.

目前我正在使用:

char *formdata = getenv("QUERY_STRING");
if(formdata == NULL) /* no data retrieved */
Run Code Online (Sandbox Code Playgroud)

这似乎与表单"GET"方法一起正常工作,但不适用于"POST"方法.如何检索POST数据?

c forms environment-variables http-post cgi-bin

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

使用cURL发布数据时,"需要长度"

<h1>Length required</h1>在向服务器提交帖子字符串时,我一直收到错误.

$cookie = "Secret cookie data here";

$searchData = array(
        '__EVENTTARGET' => 'ctl00$main$btn',
        'ctl00$main$tbMNr' => $_GET['smth'],
        'ctl00$main$tbMb' => $_GET['smthElse'],
        '__VIEWSTATE' => 'smthElseHere'
);

// Commenting this out, as suggested by user lonesomeday
//foreach ($searchData as &$elem) // This should not be necessary
//    $elem = urlencode($elem);


// create a new cURL resource

$fields = http_build_query($searchData); // Assuming it's an array

if ($ch = curl_init("http://mysite.com"))
{
        // set URL and other appropriate options
        curl_setopt($ch, CURLOPT_COOKIE, $cookie);
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); …
Run Code Online (Sandbox Code Playgroud)

php curl http-post http-error

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

如何在django 1.3中获取POST数据

嘿,我正在学习本教程,学习用Django制作一个wiki页面.但是,它是在django 0.96中制作的,我使用的是Django 1.3,所以有些东西是不同的.有些我已经修好了自己,然而这个我似乎无法使它成功.

我制作了一个将数据提交给视图的表单.这是形式:

<form method="post" action"/wikicamp/{{page_name}}/save/">{% csrf_token %}
    <textarea name="content" rows="20" cols="60">{{content}}</textarea><br>
    <input type="submit" value="Save Page"/>
</form>
Run Code Online (Sandbox Code Playgroud)

和/ wikicamp/{{page_name}}/save/url重定向到save_page视图:

from django.http import HttpResponseRedirect
from django.core.context_processors import csrf

def save_page(request, page_name):
    c = {}
    c.update(csrf(request))
    content = c.POST["content"]
    try:
        page = Page.objects.get(pk=page_name)
        page.content = content
    except Page.DoesNotExist:
        page = Page(name=page_name, content=content)
    page.save()
    return HttpResponseRedirect("wikicamp/" + page_name + "/")
Run Code Online (Sandbox Code Playgroud)

但问题是我收到此错误:

Help

Reason given for failure:

    CSRF token missing or incorrect.


In general, this can occur when there is a genuine Cross …
Run Code Online (Sandbox Code Playgroud)

python django http-post django-1.3

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

在Flask中使用url_for发出POST请求

我正在尝试在Flask的Jinja模板中发出POST请求.但是,默认情况下,参数通过GET传入,并且此特定方法仅接受POST请求.

我尝试指定_method,如下所示,但它仍然使用GET而不是POST传递参数.

<li><a href = "{{ url_for('save_info', _method='POST', filepath=s.name ) }}"><div class="nodes">{{ s.title}} - {{ song.owner }}</div></a></li>
Run Code Online (Sandbox Code Playgroud)

(无论我是否,错误信息都是一样的specify _method).

python http-post jinja2 flask

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

JAVA中带有JSON字符串的HTTP POST请求

我必须使用我已生成的JSON字符串发出http Post请求.我尝试了两种不同的方法:

1.HttpURLConnection
2.HttpClient
Run Code Online (Sandbox Code Playgroud)

但我从他们两个得到了相同的"不需要的"结果.到目前为止,我的代码与HttpURLConnection是:

public static void SaveWorkflow() throws IOException {
    URL url = null;
    url = new URL(myURLgoeshere);
    HttpURLConnection urlConn = null;
    urlConn = (HttpURLConnection) url.openConnection();
    urlConn.setDoInput (true);
    urlConn.setDoOutput (true);
    urlConn.setRequestMethod("POST");
    urlConn.setRequestProperty("Content-Type", "application/json");
    urlConn.connect();

    DataOutputStream output = null;
    DataInputStream input = null;
    output = new DataOutputStream(urlConn.getOutputStream());

                /*Construct the POST data.*/
    String content = generatedJSONString;

    /* Send the request data.*/
    output.writeBytes(content);
    output.flush();
    output.close();

    /* Get response data.*/
    String response = null;
    input = new DataInputStream (urlConn.getInputStream());
    while …
Run Code Online (Sandbox Code Playgroud)

java json httpclient http-post httpurlconnection

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

更新到5.1.0后将数据发布到WebApi失败

我有一个使用webapi加载/保存数据的Web应用程序所有用于工作正常/今天我发现有一个更新到ASP.NET MVC/webapi,我安装了更新但是之后使用jquery的POSTing数据不再有效.我在客户端代码或webapi控制器中没有做任何更改.

我的典型POSt语句如下所示:

showProgress(true, self.PanelID(), 'Saving...')
j$.ajax({
    type: "POST",
    url: uri,
    data: dataObj,
    error: function (jqXHR, status, error) {
        showProgress(false);
        GLOBAL.setMessage(self, 'Error saving ' + opType + '<br>' + error, true);
    },
    success: function (data, status, jqXHR) {
        showProgress(false);
        if (status === 'success') {
        GLOBAL.setMessage(self, opType + " saved ok");
        //....
Run Code Online (Sandbox Code Playgroud)

$ .ajax代码收到以下错误

"An error has occurred."

ExceptionMessage
    "This method or property is not supported after HttpRequest.Form, Files, InputStream, or BinaryRead has been invoked."

ExceptionType
    "System.Web.HttpException"

StackTrace
at System.Web.HttpRequest.GetInputStream(Boolean persistEntityBody, …

asp.net jquery http-post asp.net-web-api

9
推荐指数
1
解决办法
3618
查看次数

jQuery.post并不总是发送表单数据

我正在使用jQuery Post函数,例如:

var fooVar = true;
var barVar = 1;
var bazVar = "baz";

$.post("url",
   {
        foo: fooVar,
        bar: barVar,
        baz: bazVar
   },
   function(){
     alert("success");
   }
);
Run Code Online (Sandbox Code Playgroud)

在我的日志中,我看到一个间歇性的问题,即"url"没有任何表单参数的请求,我只有一个函数调用它.

是否有一种情况可以触发POST请求,而不发送jQuery Post中指定的表单参数?


我希望看到:

富=真巴= 1&巴兹=巴兹

但是根本没有表格参数:


更新:这个问题似乎主要是在Internet Explorer浏览器(IE7-IE11)上查看统计数据,但它不是IE独有的(Chrome,Firefox也有问题).

javascript jquery post http-post jquery-post

9
推荐指数
1
解决办法
952
查看次数

AngularJS - POST后刷新

在Angular中的http POST请求后刷新内容的正确方法是什么?

//controller.js
var hudControllers = angular.module('hudControllers', []);

hudControllers.controller('PropertyDetailsCtrl', 
  ['$scope','$window','$http', function ($scope,$window,$http) {

   //I want to reload this once the newCommentForm below has been submitted
   $http.get('/api/comments')
    .success(function(data) {$scope.comments = {"data":data};}})
    .error(function(data) {...);

   $scope.newCommentForm = function(){

      newComment=$scope.newComment;
      requestUrl='/api/comments';
      var request = $http({method: "post",url: requestUrl,data: {...}});
      request.success(function(){
        //How do I refresh/reload the comments?
        $scope.comments.push({'comment':'test'}); //Returns error - "TypeError: undefined is not a function"
      });
  };

}]);

//template.ejs
<div class="comment">
  <ul>
     <li ng-repeat="comment in comments.data">{{comment.comment}}</li>
 </ul>
</div>
Run Code Online (Sandbox Code Playgroud)

谢谢.

javascript http-post angularjs

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

导出Crashlytics崩溃报告日志

我需要将Crashlytics Crashes Report Log导出到某个外部文件系统中.使用他们的钩子将不起作用,因为那些仅用于新报告,而我需要导出完整的未解决问题.我找到了这个库:https://github.com/MattNewberry/crashstats但似乎Crashlytics阻止它工作.

看一下chrome调试器,我正在尝试使用curl将调用复制到他们的API,以便稍后我可以用Java/Ruby编写代码:

$ curl --data"email=user@example.com&password=pass"--referer" https:// w ww.crashlytics.com/login"--header"接受:application/json,text/javascript,*/*; q = 0.01"--header"X-CSRF-Token:E5puPaolZYUNJ2IbUX2u9S + W0iqU/6/9KDr4ivcmOq0 =" - header"X-CRASHLYTICS-DEVELOPER-TOKEN:0bb5ea45eb53fa71fa5758290be5a7d5bb867 e77"--header"X-Requested-With:XMLHttpRequest " https://www.crashlytics.com/api/v2/session

但我继续得到以下回应:

{"message":"请求无效"}

curl http-post crashlytics

9
推荐指数
0
解决办法
1640
查看次数