我正在做的小应用程序接收一些带有UTF-8编码的XML,浏览器中的XML非常正确地呈现字符,而在Android中我有一些"垃圾",例如.WÅochy而不是Włochy或Dwójka而不是Dwójka.显然我做错了什么,任何人都可以帮我搞清楚吗?
最好的祝福
String response = EntityUtils.toString( resEntity ).trim();
Log.i( CLASS_NAME, "RESPONSE=" + response );
//This returns response with incorrectly rendered characters eg. WÅochy instead of W?ochy
Run Code Online (Sandbox Code Playgroud)
以下是发送POST请求并接收响应的代码,它在AsyncTask中运行:
protected Document doInBackground(ServiceQuery... queries)
{
if ( m_sGateway == null ) return null;
Document result = null;
try
{
HttpClient client = new DefaultHttpClient();
HttpPost post = new HttpPost( m_sGateway );
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add( new BasicNameValuePair( "mdsXML", queries[0].getQueryString() ) );
UrlEncodedFormEntity ent = new UrlEncodedFormEntity( params, HTTP.UTF_8 );
post.setEntity( ent …Run Code Online (Sandbox Code Playgroud) 任何人都可以指出我正确的方向我需要在客户注册或从Magento购买第三方服务器时发送HTTP帖子?
这将是基本信息,如姓名,地址,邮政编码,电子邮件等.
不知道从哪里开始 ?
非常感谢
我一直在努力在.NET 4.0中设置WCF REST服务.我有GET请求工作,但任何涉及POST数据到服务器的请求都失败了HTTP 400 Bad Request.
这是我的简单服务:
[ServiceContract]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall)]
public class Service1
{
[WebGet(UriTemplate = "")]
public string HelloWorld()
{
return "hello world";
}
[WebInvoke(UriTemplate = "", Method = "POST")]
public string HelloWorldPost(string name)
{
return "hello " + name;
}
}
Run Code Online (Sandbox Code Playgroud)
我的Web.config:
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true">
<add name="UrlRoutingModule" type="System.Web.Routing.UrlRoutingModule, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
</modules>
</system.webServer>
<system.serviceModel>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>
<protocolMapping>
<add scheme="http" binding="webHttpBinding" /> …Run Code Online (Sandbox Code Playgroud) 在我的情况下,我有一个带登录名和密码的小表单,一旦提交,登录/通行证用于打开一个imap conn来检索用户的电子邮件,一旦在同一个动作中检索到的电子邮件数组,我想重定向到另一个动作是使用该阵列的其他treatements!
怎么可能?我的意思是重定向到另一个动作并将整个数组作为post参数发送?
以下是控制器和视图.单击[提交]按钮时,应用程序会引发错误"无法找到资源".我知道使用Get和Post是MVC的非常基本的概念.在使用Get和Post以及使用以下代码时错误的情况下,是否有任何实际情况可以让我明白这个概念.
namespace MVCModelBinding.Controllers
{
public class HomeController : Controller
{
public ActionResult Index()
{
return View();
}
[HttpPost, ActionName("Index")]
public ActionResult IndexPost()
{
if (Request.Form.Count > 0)
{
string id = Request.Form["ID"];
string fname = Request.Form["FirstName"];
string lname = Request.Form["LastName"];
ViewBag.StatusMessage = "Employee data received successfully for ID " + id + "!";
}
return View();
}
public ActionResult About()
{
return View();
}
}
}
Run Code Online (Sandbox Code Playgroud)
@using (Html.BeginForm("IndexPost", "HomeController",FormMethod.Post))
{
<table>
<tr>
<td>
Employee ID
</td>
<td>
@Html.TextBox("ID") …Run Code Online (Sandbox Code Playgroud) 一段时间以来一直试图找出这个问题.我正在使用带有json主体的HttpClient.execute向我的服务器api发布一个帖子请求.在正常的wifi和大多数3g下正常工作,但特别是在带有AT&T数据蛋白的手机上并且它在3g上,当我尝试执行请求时,我得到了一个HttpResponseException状态代码422.对422进行了一些研究并且它说它应该到期至:
"422 Unprocessable Entity(WebDAV)(RFC 4918),请求格式正确,但由于语义错误而无法遵循."
所以我猜测请求的结果出了问题,但我在形成请求方面做了同样的事情,无论我是wifi还是3g.有关可能导致此错误的原因的任何想法?
编辑:看起来我的服务器正在捕获具有伪造保护的帖子.关闭它,错误停止,但api没有通过.挖得更深一些并打印出服务器实际收到的内容,做了wifi开关之间的比较,注意到两个不同之处.首先,身体在3g上是空的,似乎它以某种方式被阻止被发送.其次,标题改变了发送的内容类型:
wifi:"HTTP_CONTENT_TYPE"=>"application/json"att 3g:"HTTP_CONTENT_TYPE"=>"text/plain; charset = ISO-8859-1,application/json"
鉴于我正在建立我的连接,我期待"application/json":
StringEntity se = new StringEntity(json.toString());
se.setContentEncoding(new BasicHeader(HTTP.CONTENT_TYPE, "application/json"));
Run Code Online (Sandbox Code Playgroud)
当我移动到3g时,为什么事情会发生变化?
更新:跑一个tcpdump,看起来我从android发送的内容与wifi和3g之间完全相同,所以似乎是提供者正在对我的数据进行更改.除HTTPS以外的任何其他提议的策略?
我正在使用JMeter进行负载测试.我的测试包含一个简单的POST请求.当我执行此请求时,服务器在其错误日志中说No Payload Detected.我已经验证服务器正在接收Post请求,并且我在Raw Post Body中尝试了不同的文本.
接下来,为了确保它不是服务器的问题,我使用了一个不同的Http Request程序(Wiztools rest客户端)来发送具有相同内容的帖子.它工作正常,不会No Payload Detected抛出任何错误.
我目前的理论是JMeter和服务器都进行解析.我知道服务器会这样做,因为它正在寻找一小块数据,并且JMeter的解析会破坏这一小块数据.
总而言之,我的问题是"JMeter做什么解析?".
我已经找到了这个答案,我唯一知道它解析的是${VARNAME}.
我发送的文字如下:
<IpReport xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="">
<ProductReviewId>12345</ProductReviewId>
<DepartmentCode>ABC</DepartmentCode>
<ProductTitle>Test of a teaser</ProductTitle>
<ProjectId>2</ProjectId>
<ProductCodePD>ICS-1139150</ProductCodePD>
<Priority>Pre-Approved</Priority>
<Status>Approved</Status>
<IpStatus>Submitted</IpStatus>
<EvalStatus>Approved</EvalStatus>
<EvalNotes>No Limitations - message from eval</EvalNotes>
<Notes>Notes test</Notes>
<IsInClarity>true</IsInClarity>
<IsPreRelease>true</IsPreRelease>
<IsApproved>true</IsApproved>
<IsCOREvalIP>false</IsCOREvalIP>
<Elements>
<IpReportElement>
<IpReportElementLineItemId>21774</IpReportElementLineItemId>
<ElementType>ReportingStatement</ElementType>
<Contributor>Sample Contributor</Contributor>
<Description>test</Description>
<LocationInProduct>test</LocationInProduct>
<ReportingStatementId>7</ReportingStatementId>
<IpCodeId>3</IpCodeId>
<Links>
<IpReportLink>
<IpReportLinkId>25982</IpReportLinkId>
<Name>Link</Name>
<Url>https://example.org/</Url>
</IpReportLink>
</Links>
</IpReportElement>
</Elements>
<CustomData><site>ldsorg</site>
<site-root>/preview/ldsorg/</site-root>
<correlation-document-id>123456-eng</correlation-document-id>
<post-to-server>l12773:9239</post-to-server>
</CustomData>
<ApprovalNumber>2013-1139150-I</ApprovalNumber>
<EvalApprovalNumber>2013-1139150-E</EvalApprovalNumber>
</IpReport>
Run Code Online (Sandbox Code Playgroud)
这是JMeter的截图.这是唯一的请求,没有其他配置元素:

我有一个"查找"WebAPI服务,它返回查询表数据,如Salutations(Mr Mrs etc)和一些更长时间(例如业务类型).
为了省去自己手动填充查找表的麻烦,我添加了一个HttpPost方法,假设我可以使用Fiddler2 简单地在主体中传递一行分隔的数据集.这样我就可以将数据列表粘贴到fiddler中,并在几秒钟内添加所有查找:
// post api/lookup/lookupName
[HttpPost]
public void SaveNewLookups([FromUri(Name="id")] string lookupName, [FromBody]string body)
Run Code Online (Sandbox Code Playgroud)
但是现在我对内容类型的尝试很重要,当命中方法时,body参数始终为null.
我通过使用以下代码来访问原始正文文本,但是让参数化版本工作会很好:
string body = Request.Content.ReadAsStringAsync().Result;
Run Code Online (Sandbox Code Playgroud)
我不想使用JSON或其他格式的数据,因为这会破坏使用简单文本列表的目的.
我使用java下面的代码创建了Web服务调用.现在我需要进行删除和执行操作.
URL url = new URL("http://example.com/questions");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setDoOutput(true);
conn.setRequestMethod( "POST" );
conn.setRequestProperty("Content-Type", "application/json");
OutputStream os = conn.getOutputStream();
os.write(jsonBody.getBytes());
os.flush();
Run Code Online (Sandbox Code Playgroud)
当我添加以下代码来执行DELETE操作时,它会给出错误说:
java.net.ProtocolException:HTTP方法DELETE不支持输出.
conn.setRequestMethod( "DELETE" );
Run Code Online (Sandbox Code Playgroud)
那么如何执行删除和放置请求?
我正在编写一些Web表单,用于测试学生编写的服务器作为练习.有些服务器不像规范工作那样完全符合规范.将Windows新行字符(即\r\n)附加到POST浏览器生成的请求会很有用,因为有些服务器正在执行ReadLine而不是使用Content-Length:标头计数.
我正在寻找生成以下请求(来自IE):
POST /Brian HTTP/1.1
Accept: text/html, application/xhtml+xml, */*
Accept-Language: en-GB
User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; Trident/7.0; rv:11.0) like Gecko
Content-Type: application/x-www-form-urlencoded
Accept-Encoding: gzip, deflate
Host: localhost:43
Content-Length: 8
DNT: 1
Connection: Keep-Alive
Cache-Control: no-cache
location
Run Code Online (Sandbox Code Playgroud)
但是追加\r\n到最后.到目前为止,我这样做的尝试是:
<form>
Username: <input type="text" name="url" id="url4"
onChange="document.getElementById('update4').setAttribute('action',
'http://localhost:43/' + document.getElementById('url4').value);"> </input>
</form>
<form id="update4" method="post" action="http://localhost:43/">
Location: <input type="text" name="isindex" id="location5"
onChange="document.getElementById('location5').value =
document.getElementById('location5').value + '\\\r\\\n'"> </input>
<input id="mysubmit3" type="submit" value="go" ></input> …Run Code Online (Sandbox Code Playgroud) http-post ×10
android ×2
http ×2
3g ×1
asp.net ×1
get ×1
html ×1
http-delete ×1
http-put ×1
httpresponse ×1
java ×1
javascript ×1
jmeter ×1
json ×1
magento ×1
newline ×1
php ×1
post ×1
razor ×1
symfony-1.4 ×1
symfony1 ×1
textinput ×1
utf-8 ×1
web-services ×1