我正在尝试使用unicode字符串(u'\ xe4\xf6\xfc')作为Python中的参数进行HTTP POST,但是我收到以下错误:
UnicodeEncodeError:'ascii'编解码器无法编码字符
这是用于进行HTTP POST的代码(使用httplib2)
http = httplib2.Http()
userInfo = [('Name', u'\xe4\xf6\xfc')]
data = urlencode(userInfo)
resp, content = http.request(url, 'POST', body=data)
Run Code Online (Sandbox Code Playgroud)
关于如何解决这个问题的任何想法?
试图弄清楚我的编码有什么问题.我从这里关注了一篇博文.
我设法获得代码实际上传文件到PHP Web服务.但是,出于某种原因,虽然我已经明确设置了文件的MIME类型,但PHP显示MIME只是一个空字符串,因此被拒绝.
这是我的编码:
public String SendPost(String fn, String bid, String caption, String uid, String APIKey, String postHash)
throws ParseException, ClientProtocolException, IOException {
HttpClient httpclient = new DefaultHttpClient();
httpclient.getParams().setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1);
HttpPost httppost = new HttpPost(UrbURL);
Log.i("POSTFN", fn);
Log.i("POSTFN", bid);
Log.i("POSTFN", caption);
Log.i("POSTFN", uid);
Log.i("POSTFN", APIKey);
Log.i("POSTFN", postHash);
String postAuth = uid + postHash;
postAuth = md5(postAuth);
postAuth = postAuth.substring(0, 16);
//Log.i("POSTAUTH", postAuth);
MultipartEntity mp = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
/*File tempImg = new File(fn);
FileBody bin = new FileBody(tempImg, "image/jpg");*/ …Run Code Online (Sandbox Code Playgroud) 如果我创建一个控制器动作并且不用它装饰它AcceptVerbs,HttpPost或者HttpGet.什么是默认行为?
该操作是否允许任何访问方法或默认为GET?
我在Adobe Acrobat中制作了一个pdf表格.现在我想创建一个按钮,将表单提交给HTTP POST请求.我搜索了大约4个小时,但我没有找到一个例子来做到这一点.
在这里,我读到可以通过HTTP提交发送pdf表单字段,但也没有给出示例:http: //acrobatusers.com/tutorials/form-submit-e-mail-demystified
我正在寻找一个可以链接到提交按钮的JavaScript示例.
我需要使用参数创建HTTP POST请求.我知道有很多例子,我尝试过使用HTTPparams,NameValuePair等,但似乎无法获得服务器的正确格式.
Server Type: REST based API utilizing JSON for data transfer
Content-type: application/json
Accept: application/json
Content-length: 47
{"username":"abcd","password":"1234"}
我可以通过这些标题但我似乎无法通过这些参数"用户名","密码".这是我的代码:
HttpClient client = new DefaultHttpClient();
HttpPost post = new HttpPost("http://www.mymi5.net/API/auth/login");
List<NameValuePair> pairs = new ArrayList<NameValuePair>();
pairs.add(new BasicNameValuePair("username","abcd"));
pairs.add(new BasicNameValuePair("password","1234"));
post.setHeader("Content-type", "application/json");
post.setHeader("Accept", "application/json");
UrlEncodedFormEntity entity = new UrlEncodedFormEntity(pairs,"UTF-8");
post.setEntity(entity);
HttpResponse response = client.execute(post);
Run Code Online (Sandbox Code Playgroud)
我试图调试,但无法看到实体是否正确连接...我做错了什么?
提前致谢.玛斯
有没有办法确定是否<asp:UpdatePanel />已执行类似于我们可以使用的Ajax回发...
if(!Page.IsPostBack) { ...snip }
Run Code Online (Sandbox Code Playgroud)
...确定是否正在进行按钮提交的回发.
我正在尝试从jQuery中检测Ajax请求,但它正在拾取UpdatePanel请求,我想要排除,例如......
if (Request.IsAjaxRequest() && !Page.IsUpdatePanelPostback)
{
// Deal with jQuery Ajax
}
Run Code Online (Sandbox Code Playgroud) 我需要在HTTP处理程序中侦听并处理HTTP POST字符串.
下面是将字符串发布到处理程序的代码 -
string test = "charset = UTF-8 & param1 = val1 & param2 = val2 & param3 = val3 & param4 = val4;
byte[] data = Encoding.UTF8.GetBytes(test);
PostData("http://localhost:53117/Handler.ashx", data);
Run Code Online (Sandbox Code Playgroud)
我在Handler中尝试的是 -
public void ProcessRequest(HttpContext context)
{
var value1 = context.Request["param1"];
}
Run Code Online (Sandbox Code Playgroud)
但它无效.如何在Handler中监听并获取参数值?
我知道有很多类似的帖子,但我还没有找到解决方案.我试图将一些xml发布到MPI网关,但不断收到以下错误:
无法从传输连接读取数据:远程主机强制关闭现有连接.
下面是我正在使用的代码,但我已经尝试了几乎所有我能想到的不同方法,它们都返回相同的错误:
string result = "";
string xml = "<TNSAuthRequest><CardNumber>0123456789</CardNumber><ExpiryDate>1801</ExpiryDate><PurchaseAmt>750</PurchaseAmt><CurrencyCode>826</CurrencyCode><CurrencyExponent>2</CurrencyExponent><CountryCode>826</CountryCode><MerchantName>Mayflower</MerchantName><MerchantId>0123456789</MerchantId><MerchantData>abcdefghijklmnopqrstuvwxyz0123456789</MerchantData><MerchantUrl>example.com</MerchantUrl><NotificationURL>example.com/basket</NotificationURL></TNSAuthRequest>";
var url = "https://mpi.securecxl.com";
byte[] bytes = System.Text.Encoding.ASCII.GetBytes("xmldata=" + xml.ToString());
ServicePointManager.ServerCertificateValidationCallback += new System.Net.Security.RemoteCertificateValidationCallback(ValidateRemoteCertificate);
var req = (HttpWebRequest)WebRequest.Create(url);
req.AllowWriteStreamBuffering = true;
req.ContentType = "text/xml";
req.Method = "POST";
//req.ContentLength = bytes.Length;
req.KeepAlive = false;
req.ProtocolVersion = HttpVersion.Version10;
req.ServicePoint.ConnectionLimit = 1;
//req.Timeout = -1;
try
{
using (var writer = new StreamWriter(req.GetRequestStream(), Encoding.ASCII))
{
writer.WriteLine(bytes);
}
using (WebResponse resp = req.GetResponse())
{
using (StreamReader sr = new StreamReader(resp.GetResponseStream()))
{
result = …Run Code Online (Sandbox Code Playgroud) 有没有办法告诉服务器更新数据而无需订阅?跳过return语句和订阅似乎使http调用变为惰性.
在我的情况下,我的数据库人创建了一堆没有返回任何内容的存储过程,有时我想在我的服务中做这样简单的事情:
public setItem(item: IRequestItem) {
this.http.post('api/items', item);
}
Run Code Online (Sandbox Code Playgroud)
并在我的组件中调用它:
save() {
var comp = this;
this.items.forEach(function(item) {
comp.service.setItem(item)
});
}
Run Code Online (Sandbox Code Playgroud)
相反,我必须在服务中做这样的事情:
public setItem(item: IRequestItem) {
return this.http.post('api/items', item);
}
Run Code Online (Sandbox Code Playgroud)
然后在conponent中像这样调用它:
save() {
var comp = this;
this.items.forEach(function(item) {
comp.service.setItem(item).subscribe(r => console.log(r));
});
}
Run Code Online (Sandbox Code Playgroud)
哪个会返回很多这些:
Response {_body: "", status: 204, ok: true, statusText: "No Content", headers: Headers…}
_body : ""
headers : Headers
ok : true
status : 204
statusText : "No Content"
type : 2
url : "http://localhost:56018/api/items"
__proto__ …Run Code Online (Sandbox Code Playgroud) 如何使用Volley库将这些参数传递给POST方法.
API链接:http
://api.wego.com/flights/api/k/2/searches?
api_key = 12345&ts_code = 123 JSON结构的屏幕截图
我试过这个但又面临错误.
StringEntity params= new StringEntity ("{\"trip\":\"[\"{\"departure_code\":\","
+departure,"arrival_code\":\"+"+arrival+","+"outbound_date\":\","
+outbound,"inbound_date\":\","+inbound+"}\"]\"}");
request.addHeader("content-type", "application/json");
request.addHeader("Accept","application/json");
Run Code Online (Sandbox Code Playgroud)
有关API的详细信息,请访问此处.
http-post ×10
android ×3
asp.net ×3
c# ×2
.net ×1
acceptverbs ×1
acrobat ×1
ajax ×1
angular ×1
ascii ×1
forms ×1
http ×1
http-get ×1
httpclient ×1
httphandler ×1
javascript ×1
mime-types ×1
observable ×1
pdf ×1
post ×1
python ×1
unicode ×1
updatepanel ×1