标签: http-post

在后退按钮上显示"网页已过期"

当用户点击后退按钮时,浏览器要求显示无处不在的"此页面已过期"消息的要求是什么?

有哪些用户友好的方法可以防止用户在webapp中使用后退按钮?

http-post

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

使用带有HTTPS证书的System.Net.WebClient

在我的C#Windows客户端中,我有一个POST提交给"母舰".当然,我希望提交的数据是安全的,所以我付了HostGator的费用来发给我SSL证书.

我保存了.CER文件,我正在构建请求:

//wrapper for WebClient object to use certificate file
class SecureWebClient : WebClient
{
    protected override WebRequest GetWebRequest(Uri address)
    {
        HttpWebRequest request = (HttpWebRequest)base.GetWebRequest(address);
        string certPath = @"e:\mycertificate.cer";
        X509Certificate myCert = X509Certificate.CreateFromCertFile(certPath);
        request.ClientCertificates.Add(myCert);
        return request;
    }
}

//request
private static SecureWebClient client = new SecureWebClient();
private static NameValueCollection = new NameValueCollection();
nvc.Add(POST_ACTION, ACTION_CODE_LOGIN);
nvc.Add(POST_EMAIL, email);
nvc.Add(POST_PASSWORD, password);

sResponse = System.Text.Encoding.ASCII.GetString(client.UploadValues(BASE_URL + ACTION_PAGE, nvc));
Run Code Online (Sandbox Code Playgroud)

它抛出一个System.Net.WebException:

底层连接已关闭:发送时发生意外错误.

InnerException是一个System.IO.IOException:

由于意外的数据包格式,握手失败.

对我做错了什么的见解?

c# https certificate http-post httpwebrequest

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

在执行POST时,无法将HttpWebRequest超时设置为高于100秒?

我遇到了一个问题,HttpWebRequest在执行POST时不会尊重超过100秒的超时值.但是,如果请求是GET,则会遵循高于100秒的超时值.在.GetResponse()调用时抛出超时异常.我正在设置我能够发现的所有超时值,但似乎我错过了一个,或者框架中有一个错误.

这是一个针对.NET Framework 3.5的C#应用​​程序,使用Visual Studio 2008构建.Web服务器是IIS 6.0,连接超时设置为默认的120秒,启用了保持活动...再次GET请求尊重超时值I指定,如果<= 100秒,POST请求将遵守超时.

这是我的代码:

int timeout = 200000; // 200 seconds
HttpWebRequest proxyRequest = (HttpWebRequest)WebRequest.Create(serverUrl);
proxyRequest.Accept = clientRequest.AcceptTypes.ToDelimitedString(", ");
proxyRequest.Method = "POST"
proxyRequest.UserAgent = clientRequest.UserAgent;
proxyRequest.Timeout =  timeout;
proxyRequest.ReadWriteTimeout = timeout;
proxyRequest.KeepAlive = false;
proxyRequest.AllowAutoRedirect = false;
proxyRequest.ServicePoint.Expect100Continue = false;
proxyRequest.ServicePoint.MaxIdleTime = timeout;
proxyRequest.ServicePoint.ConnectionLeaseTimeout = -1;

try
{
    // add post data
    request.ContentType = "application/x-www-form-urlencoded";
    byte[] postData = Encoding.UTF8.GetBytes("somedata=7&moredata=asdf");
    // set some post data
    request.ContentLength = postData.Length;
    using (Stream stream = request.GetRequestStream())
    {
        stream.Write(postData, 0, …
Run Code Online (Sandbox Code Playgroud)

c# timeout http-post httpwebrequest

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

更新资源时,更新成功时返回什么HTTP状态代码?

所以我有一个网站接受HTTP-PUT特定资源,例如./contact这将允许消费者更新联系人,假设他们已通过验证.

所以我更新了记录,一切都很好..现在我需要向消费者返回一些内容.

什么是我应该返回的HTTP状态代码?

如果这是一个HTTP-POST(即创建一个-new-资源),那么我将返回一个201 Created并添加一个Locationheader属性.

但是......我找不到任何关于如何为更新做的线索.

干杯:)

rest http-post http-status-codes http-put

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

Android错误:MultipartEntity,客户端发送的请求在语法上不正确

我想通过安全的restful web服务发送歌曲(mp3/wav)文件和一些数据.我正在使用MultipartEntity来发出HttpPost请求.但是当我通过HttpClient执行它时,服务器会回复此错误

HTTP状态400 - 错误请求类型:状态报告消息:错误请求客户端发送的请求在语法上不正确(错误请求).

但是,如果我们从Web界面调用它,那么该服务的效果非常好.请帮忙

它的代码

HttpClient httpclient = new DefaultHttpClient();
HttpPost postRequest = new HttpPost();
        try {
            MultipartEntity reqEntity = new MultipartEntity();

            reqEntity.addPart("email", new StringBody("test@testmail.com"));
            reqEntity.addPart("password", new StringBody("123"));
            reqEntity.addPart("title", new StringBody("My new song"));
            reqEntity.addPart("musicData", new FileBody(new File(FilePath))); 

            // FIlePath is path to file and contains correct file location

            postRequest.setEntity(reqEntity);

            postRequest.setURI(new URI(ServiceURL));
            HttpResponse response = httpclient.execute(postRequest);

        } catch (URISyntaxException e) {
            Log.e("URISyntaxException", e.toString());
        } 
Run Code Online (Sandbox Code Playgroud)

我还为MultipartEntity提供了apache-mime4j,httpclient,httpcore和httpmime jar.

这是服务的HTML页面捕捉. 在此输入图像描述

java android httpclient http-post multipartentity

12
推荐指数
1
解决办法
2939
查看次数

django ajax post 403禁止

使用django 1.4即时获取403错误当我尝试从我的javascript做一个帖子做我的django服务器.虽然问题只在于帖子,但我的工作正常.也试过@csrf_exempt没有运气

更新:我现在可以发帖添加{% csrf_token %},但是后期响应是空的,虽然GET正确,任何想法?

我的django观点:

@csrf_protect
def edit_city(request,username):
    conditions = dict()

    #if request.is_ajax():
    if request.method == 'GET':
        conditions = request.method

    elif request.method == 'POST':
        print "TIPO" , request.GET.get('type','')       
        #based on http://stackoverflow.com/a/3634778/977622     
        for filter_key, form_key in (('type',  'type'), ('city', 'city'), ('pois', 'pois'), ('poisdelete', 'poisdelete'), ('kmz', 'kmz'), ('kmzdelete', 'kmzdelete'), ('limits', 'limits'), ('limitsdelete', 'limitsdelete'), ('area_name', 'area_name'), ('action', 'action')):
            value = request.GET.get(form_key, None)
            if value:
                conditions[filter_key] = value
                print filter_key , conditions[filter_key]

        #Test.objects.filter(**conditions)
    city_json = json.dumps(conditions)

    return HttpResponse(city_json, mimetype='application/json')
Run Code Online (Sandbox Code Playgroud)

这是我的javascript代码:

function …
Run Code Online (Sandbox Code Playgroud)

javascript django ajax http-post http-status-code-403

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

使用OAuth-Signpost和Apache HttpComponents签署POST请求的正确方法是什么?

我目前正在使用OAuth-Signpost Java库来签署从客户端发送到实现OAuth身份验证的服务器的请求.在进行GET请求时(使用HttpURLConnection)一切正常:请求被签名,参数被包含,签名在目的地中匹配.但是,它似乎不适用于POST请求.我知道使用HttpURLConnection签名POST时可能出现的问题,因此我转移到Apache HttpComponents库以获取这些请求.我在以下示例中发送的参数是纯字符串和类似XML的字符串('rxml').我的代码如下:

public Response exampleMethod(String user, String sp, String ep, String rn, String rxml){

   //All these variables are proved to be correct (they work right in GET requests)
    String uri = "...";
    String consumerKey = "...";
    String consumerSecret = "...";
    String token = "...";
    String secret = "...";

  //create the parameters list
    List<NameValuePair> params = new ArrayList<NameValuePair>();
    params.add(new BasicNameValuePair("user", user));
    params.add(new BasicNameValuePair("sp", sp));
    params.add(new BasicNameValuePair("ep", ep));
    params.add(new BasicNameValuePair("rn", rn));
    params.add(new BasicNameValuePair("rxml", rxml));

   // create a consumer object and configure …
Run Code Online (Sandbox Code Playgroud)

java oauth http-post signpost apache-httpcomponents

12
推荐指数
1
解决办法
9197
查看次数

如何在Android中将多部分表单数据和图像上传到服务器?

在Android代码中将多部分实体映像上传到服务器期间的状态代码500

Html格式:( 可以成功添加图像到服务器)

 <form method="post" action="http://xyz/upload_picture" enctype="multipart/form-data">

      Sample Picture Upload Form Submit

      <br/><br/>

      API key: <input type="text" name="key" value="abc"><br/><br/>
      Login: <input type="text" name="login" value="text"><br/>
      Password: <input type="password" name="password" value="text"><br/><br/>

      Property ID:<input type="text" name="property_id" value="111"><br/>
      Picture File:<input type="file" name="picture"><br/><br/>

      <br/><br/>
      <input type="submit" name="" value="Upload Picture"><br/>

    </form>
Run Code Online (Sandbox Code Playgroud)

Android代码:( 状态代码500)

   HttpClient httpclient = new DefaultHttpClient();
            HttpPost httppost = new HttpPost(
                    "http://xyz/upload_picture");

            try {
                MultipartEntity entity = new MultipartEntity();

                entity.addPart("key", new StringBody("abc"));
                entity.addPart("login", new StringBody("abc"));
                entity.addPart("password", new StringBody("test"));
                entity.addPart("property_id", new StringBody("111"));


                File file = …
Run Code Online (Sandbox Code Playgroud)

android multipartform-data http-post

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

Android:使用MultiPartEntityBuilder上传Image和JSON

我尝试将数据上传到服务器,我的数据包含多个图像和大JSON,在它之前,我尝试使用转换图像发送到字符串使用base64并发送我之前转换的另一个数据和图像JSON,但我OutOfMemory在这里遇到问题,所以我读了一个说我必须尝试使用​​的解决方案MultipartEntityBuilder.我仍然感到困惑,不明白该怎么做MultiPartEntityBuilder,有没有人可以帮助我这样做MultiPartEntityBuilder?这是我的代码:

    try{
    //membuat HttpClient
    //membuat HttpPost
    HttpPost httpPost= new HttpPost(url);
    SONObject jsonObjectDP= new JSONObject();
    System.out.println("file audio "+me.getModelDokumenPendukung().getAudio());
    jsonObjectDP.put("audio_dp",MethodEncode.EncodeAudio(me.getModelDokumenPendukung().getAudio()));
    jsonObjectDP.put("judul_audio",me.getModelDokumenPendukung().getJudul_audio());
    jsonObjectDP.put("ket_audio",me.getModelDokumenPendukung().getKet_audio());
    JSONArray ArrayFoto= new JSONArray();

    //This loop For my multiple File  Images
    List<ModelFoto>ListFoto=me.getModelDokumenPendukung().getListFoto();
    for (int i=0; i<ListFoto.size();i++) {
        JSONObject jsonObject= new JSONObject();
        jsonObject.put("foto", ListFoto.get(i).getFile_foto());
        jsonObject.put("judul_foto", ListFoto.get(i).getJudul_foto());
        jsonObject.put("ket_foto", ListFoto.get(i).getKet_foto());
        ArrayFoto.put(jsonObject);

    }

    JSONObject JSONESPAJ=null;
     JSONESPAJ = new JSONObject();
     JSONObject JSONFINAL = new JSONObject();
            JSONESPAJ.put("NO_PROPOSAL",me.getModelID().getProposal());
            JSONESPAJ.put("GADGET_SPAJ_KEY",me.getModelID().getIDSPAJ());
            JSONESPAJ.put("NO_VA",me.getModelID().getVa_number());
            JSONESPAJ.put("Dokumen_Pendukung",jsonObjectDP);

            JSONFINAL.put("ESPAJ", JSONESPAJ); …
Run Code Online (Sandbox Code Playgroud)

android json http-post multipartentity

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

获取使用PHP5传输的字节用于POST请求

注意我是PHP,Apache和服务器编程的新手,因此将会有更详尽的解释.


上下文

我在javascript中创建了一个进度条,用于在上传文件时显示.当前我以设定的帧速率更新进度条(以查看它是否有效).

显然,为了使其成为准确的进度条,一切都应该与传输的字节数相比,与总字节数相比较.

使用PHP5如何获取有关与文件总字节数相关的传输字节数的信息,以便我可以将其传递给JS函数updateProgress(bytesSoFar, totalBytes)来更新我的进度条?请详细告诉我下面代码所需的修改,以使其工作.我见过xhr一些例子,但它们并不完全可以访问.

我刚刚设置了LocalHost并使用了W3Schools的PHP文件上传教程.要使模拟的"上传"工作,我按照此SO 帖子的建议更改了本地权限.我不一定需要读取文件,我只想知道已传输的许多字节.


目前我有两个文件:

  • 的index.php

  • upload.php的

的index.php

<!DOCTYPE html>
<html>
<body>

<form action="upload.php" method="post" enctype="multipart/form-data">
    Select image to upload:
    <input type="file" name="fileToUpload" id="fileToUpload">
    <input type="submit" value="Upload Image" name="submit">
</form>

</body>
</html>
Run Code Online (Sandbox Code Playgroud)

upload.php的

<?php
$target_dir = "uploads/";
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
$uploadOk = 1;
$imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);
// Check if image file is a actual image or fake image
if(isset($_POST["submit"])) {
    $check = …
Run Code Online (Sandbox Code Playgroud)

javascript php post http-post

12
推荐指数
1
解决办法
592
查看次数