标签: http-post

使用带有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万
查看次数

用于测试的HTTP Post Multipart Tool

有没有人知道一个小测试工具(如Firefox的Rest/RestTool)能够上传文件并在同一个帖子请求(Multipart)中发送文本正文?

rest http http-post firefox-addon

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

目标主机不能为空,或者在参数中设置

我收到此错误"目标主机不能为空,或在参数中设置".我的清单文件设置了互联网权限,我在我的网址之前放了"http://".它仍然会出现同样的错误.我的网址没有"www".附在它上面.

我的代码的一部分:

HttpPost post = new HttpPost("http://infocreation.something_something1.xml");
Run Code Online (Sandbox Code Playgroud)

我的部分内容如下:

<uses-permission android:name="android.permission.INTERNET/>
Run Code Online (Sandbox Code Playgroud)

现在我该怎么做?

android http-post android-manifest

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

为异步FormUrlEncoded DELETE调用改进抛出IllegalArgumentException异常

我正在尝试创建一个异步POST和DELETE,这是使用Android 4.4中的Retrofit编码的url形式

这是我的客户 -

@FormUrlEncoded
@POST(INetwork.API_BASE_PREFIX + "/memberships.json")
void join(@Field("id") String id, Callback<?> cb);

@FormUrlEncoded
@DELETE(INetwork.API_BASE_PREFIX + "/memberships.json")
void leave(@Field("id") String id, Callback<?> cb);
Run Code Online (Sandbox Code Playgroud)

这是例外 -

java.lang.IllegalArgumentException: IRepositoryClient.leave: FormUrlEncoded can only be specified on HTTP methods with request body (e.g., @POST).
        at retrofit.RestMethodInfo.methodError(RestMethodInfo.java:118)
        at retrofit.RestMethodInfo.parseMethodAnnotations(RestMethodInfo.java:191)
        at retrofit.RestMethodInfo.init(RestMethodInfo.java:128)
        at retrofit.RestAdapter$RestHandler.invokeRequest(RestAdapter.java:329)
        at retrofit.RestAdapter$RestHandler.access$100(RestAdapter.java:264)
        at retrofit.RestAdapter$RestHandler$2.obtainResponse(RestAdapter.java:315)
        at retrofit.CallbackRunnable.run(CallbackRunnable.java:42)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
        at retrofit.Platform$Android$2$1.run(Platform.java:142)
        at java.lang.Thread.run(Thread.java:841)
Run Code Online (Sandbox Code Playgroud)

我查看了源代码,基本上如果方法没有正文并且请求是formurlencoded,则抛出此异常.另外我注意到FormUrlEncoded的所有例子都工作正常,因为它不是异步的,即我有某种类型的返回类型而且没有回调 - 抱歉我有点丢失

我应该送一个空身吗?我需要发送一个,而且@Field参数不够吗?

使用Retrofit 1.5.0

post android http-post http-delete retrofit

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

如何在codeigniter中检查请求是否是POST或GET请求?

我只是想知道是否有一种非常简单的方法来确定请求是$_POST一个$_GET请求还是一个请求.

这是否Codeigniter有这样的事情?

$this->container->isGet();
Run Code Online (Sandbox Code Playgroud)

php codeigniter http-get http-post request

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

Selenium:尝试使用Cookie登录 - "只能为当前域设置Cookie"

我想要实现的目标

我正在尝试登录到必须使用Selenium无头启用cookie的网站,我使用PhantomJS作为驱动程序.

问题

我首先使用Selenium IDE记录了这个程序,它使用Firefox(不是无头)工作正常.然后我将代码导出到Python,现在我无法登录,因为它抛出错误"只能为当前域设置Cookie".我不知道为什么我会遇到这个问题,我不在正确的域名上吗?

码

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import Select
import unittest, time, re

        self.driver = webdriver.PhantomJS()
        self.driver.implicitly_wait(30)
        self.base_url = "https://login.example.com"

        driver = self.driver
        driver.get(self.base_url)

        all_cookies = self.driver.get_cookies()

        # It prints out all cookies and values just fine
        for cookie in all_cookies
            print cookie['name'] + " --> " + cookies['value']

        # Set cookies to driver
        for s_cookie in all_cookies:
            c = { s_cookie['name'] : s_cookie['value']}
            # This is …
Run Code Online (Sandbox Code Playgroud)

python cookies post selenium http-post

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

获取使用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
查看次数

MVC - 编辑对象列表

我在MVC中有以下类布局:

public class ReportModel 
{
    List<SomeItem> items;
    string value;
    string anotherValue;
}
Run Code Online (Sandbox Code Playgroud)

现在我在这种类型的MVC中创建一个强类型视图,并使可编辑的文本字段编辑每个值,并使用foreach循环填充文本字段以编辑someitem列表中的项目.

当我提交到httppost方法时,单个值在reportmodel对象中返回正常,但列表不会在对象中返回.该怎么做?

当我说httppost时,我指的是MVC发回的方法

[HttpPost]
public ActionResult EditReport(ReportModel report)
{
    // Save the report in here after the update on the UI side
}
Run Code Online (Sandbox Code Playgroud)

查看发布someitem列表的代码

if (Model.items != null && Model.items.Count > 0)
{
    for (int i = 0; i < Model.items.Count; i++)
    {                
        <div class="editrow">
            <div class="edititem">
                <div class="editor-label">
                    @Html.LabelFor(m => m.items.ElementAt(i).propertyOne)
                </div>
                <div class="editor-field">
                    @Html.TextBoxFor(m => m.items.ElementAt(i).propertyOne)
                    @Html.ValidationMessageFor(m => m.items.ElementAt(i).propertyOne)
                </div>
            </div>
            <div class="edititem">
                <div class="editor-label">
                    @Html.LabelFor(m …
Run Code Online (Sandbox Code Playgroud)

asp.net-mvc http-post

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

使用Google Apps脚本发布JSON数据

Server response  :  HTTP Status 415 - Unsupported Media Type
Run Code Online (Sandbox Code Playgroud)

我试图从谷歌脚本发布JSON数据到URL,但得到上述错误.这是我的代码:

function myFunctionpost() {
  var url = "http://abc.xyz.org/jira/rest/api/2/issue";
  var data = {"project":{ "key": "KEY"},"summary": "create issue.", "description":                 "Creating of an issue from google spreadsheet using the REST API", "issuetype": {"name": "Bug"}}  ;
   var payload = JSON.stringify(data);

   var headers = { "Accept":"application/json", 
              "Content-Type":"application/json", 
              "Authorization":"Basic _authcode_"
             };

   var options = { "method":"POST",
                "headers": headers,
                "payload" : payload
               };
   var response = UrlFetchApp.fetch(url, options);
 Logger.log(response);  

 }
Run Code Online (Sandbox Code Playgroud)

我尝试更改内容类型但没有工作.auth代码正常工作,因为我能够从URL获取.

有人知道我哪里出错吗?谢谢.

json content-type jira http-post google-apps-script

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

Laravel 4使用数据从控制器向外部URL发出请求

我正在寻找一种方法来从控制器发出一个发布请求到外部网址.发布的数据是一个php数组.要接收的网址是外部网址中的电子商务API.帖子必须从控制器方法完成.该网址应回复"成功","错误","失败"或"trylater"字符串.我试过以下但没有成功:

    return Redirect::to("https://backoffice.host.iveri.com/Lite/Transactions/New/Authorise.aspx", compact($array));
Run Code Online (Sandbox Code Playgroud)

我也试过卷曲:

    $url = 'https://backoffice.host.iveri.com/Lite/Transactions/New/Authorise.aspx';
    //url-ify the data for the POST
    $fields_string ='';
    foreach($array as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
    rtrim($fields_string,'& ');

    //open connection
    $ch = curl_init();

    //set the url, number of POST vars, POST data
    curl_setopt($ch,CURLOPT_URL, $url);
    curl_setopt($ch,CURLOPT_POST, count($array));
    curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

    //execute post
    $result = curl_exec($ch);

    //close connection
    curl_close($ch);
Run Code Online (Sandbox Code Playgroud)

要发送的数组的一部分是API用于响应的回调:

'Lite_Website_Successful_url' => 'https://mydomain.com/order/'.$order_id,
'Lite_Website_Fail_url' => 'https://mydomain.com/checkout/fail',
'Lite_Website_TryLater_url' => 'https://mydomain.com/checkout/trylater',
'Lite_Website_Error_url' => 'https://mydomain.com/checkout/error'
Run Code Online (Sandbox Code Playgroud)

请告诉我如何使用随附的数据正确地发送POST请求到外部URL.来自控制器的ajax帖子也会有所帮助,但我尝试过没有成功.但我更喜欢laravel php的答案.谢谢.

php curl http-post laravel laravel-4

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