我有一个自定义的CMS我已经构建,在我的开发盒(Ubuntu/PHP5 +/MySQL5 +)上完美运行.
我只是将它移动到我的客户端的生产框中,现在所有表单提交都显示为空的$ _POST数组.
我找到了一个技巧来验证数据实际上正在使用file_get_contents('php://input');并且数据在那里显示正常 - $_POST/ $_REQUEST数组总是为空.
我还通过firebug(application/x-www-form-urlencoded; charset=utf-8)验证了内容类型标题是正确的.
无论表单是通过AJAX提交还是通过常规表单提交,都会发生此问题.
任何帮助是极大的赞赏!
我正在通过AJAX将表单字段的内容发布到PHP脚本并使用JavaScript escape(field_contents).问题是任何加号都被剥离并被空格所取代.如何安全地'编码'加号然后在PHP端适当地"解码"它?
我想发送一个字符串作为ajax Post参数.
以下代码:
$.ajax({
type: "POST",
url: "http://nakolesah.ru/",
data: 'foo=bar&ca$libri=no$libri',
success: function(msg){
alert('wow'+msg);
}
});
Run Code Online (Sandbox Code Playgroud)
不管用.为什么?
我试图从HttpServletRequest对象获取整个身体.
我关注的代码如下所示:
if ( request.getMethod().equals("POST") )
{
StringBuffer sb = new StringBuffer();
BufferedReader bufferedReader = null;
String content = "";
try {
//InputStream inputStream = request.getInputStream();
//inputStream.available();
//if (inputStream != null) {
bufferedReader = request.getReader() ; //new BufferedReader(new InputStreamReader(inputStream));
char[] charBuffer = new char[128];
int bytesRead;
while ( (bytesRead = bufferedReader.read(charBuffer)) != -1 ) {
sb.append(charBuffer, 0, bytesRead);
}
//} else {
// sb.append("");
//}
} catch (IOException ex) {
throw ex;
} finally {
if (bufferedReader != null) { …Run Code Online (Sandbox Code Playgroud) 每次我想用jQuery向Jails发布一个JSON对象数组时,我就遇到了这个问题.如果我对数组进行字符串化,我可以看到jQuery正在正常工作:
"shared_items"=>"[{\"entity_id\":\"253\",\"position\":1},{\"entity_id\":\"823\",\"position\":2}]"
Run Code Online (Sandbox Code Playgroud)
但是如果我只是将它作为AJAX调用的数据发送给我:
"shared_items"=>{"0"=>{"entity_id"=>"253", "position"=>"1"}, "1"=>{"entity_id"=>"823", "position"=>"2"}}
Run Code Online (Sandbox Code Playgroud)
然而,如果我只发送一个普通数组,它的工作原理:
"shared_items"=>["entity_253"]
Run Code Online (Sandbox Code Playgroud)
为什么Rails将数组更改为那个奇怪的哈希?想到的唯一原因是Rails无法正确理解内容,因为这里没有类型(有没有办法在jQuery调用中设置它?):
Processing by SharedListsController#create as
Run Code Online (Sandbox Code Playgroud)
谢谢!
更新:
我将数据作为数组发送,而不是字符串,并使用该.push()函数动态创建数组.尝试$.post和$.ajax,相同的结果.
我想从JavaScript发送一些变量和一个带POST方法的字符串.我从数据库中获取字符串,然后将其发送到PHP页面.我正在使用XMLHttpRequest对象.问题是字符串包含字符"&"几次,PHP中的$ _POST数组看起来像多个键.我尝试用"/"替换"&"和replace()函数,但似乎没有做任何事情.有人可以帮忙吗?
javascript代码和字符串如下所示:
var wysiwyg = dijit.byId("wysiwyg").get("value");
var wysiwyg_clean = wysiwyg.replace('&','\&');
var poststr = "act=save";
poststr+="&titlu="+frm.value.titlu;
poststr+="§iune="+frm.value.sectiune;
poststr+="&wysiwyg="+wysiwyg_clean;
poststr+="&id_text="+frm.value.id_text;
xmlhttp.open("POST","lista_ajax.php",true);
xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
xmlhttp.send(poststr);
Run Code Online (Sandbox Code Playgroud)
字符串是:
<span class="style2">"Busola"</span>
Run Code Online (Sandbox Code Playgroud) 我有以下内容:
final String url = "http://example.com";
final HttpClient httpClient = new HttpClient();
final PostMethod postMethod = new PostMethod(url);
postMethod.addRequestHeader("Content-Type", "application/json");
postMethod.addParameters(new NameValuePair[]{
new NameValuePair("name", "value)
});
httpClient.executeMethod(httpMethod);
postMethod.getResponseBodyAsStream();
postMethod.releaseConnection();
Run Code Online (Sandbox Code Playgroud)
它不断回来500.服务提供商说我需要发送JSON.如何使用Apache HttpClient 3.1+完成这项工作?
我想将一些表单数据发布到不在我自己的Web应用程序中的指定URL.它具有相同的域,例如"domain.client.nl".Web应用程序有一个URL"web.domain.client.nl",我要发布到的URL是"idp.domain.client.nl".但我的代码什么也没做.....有人知道我做错了吗?
沃特
StringBuilder postData = new StringBuilder();
postData.Append(HttpUtility.UrlEncode(String.Format("username={0}&", uname)));
postData.Append(HttpUtility.UrlEncode(String.Format("password={0}&", pword)));
postData.Append(HttpUtility.UrlEncode(String.Format("url_success={0}&", urlSuccess)));
postData.Append(HttpUtility.UrlEncode(String.Format("url_failed={0}", urlFailed)));
ASCIIEncoding ascii = new ASCIIEncoding();
byte[] postBytes = ascii.GetBytes(postData.ToString());
// set up request object
HttpWebRequest request;
try
{
request = (HttpWebRequest)HttpWebRequest.Create(WebSiteConstants.UrlIdp);
}
catch (UriFormatException)
{
request = null;
}
if (request == null)
throw new ApplicationException("Invalid URL: " + WebSiteConstants.UrlIdp);
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";
request.ContentLength = postBytes.Length;
request.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322; .NET CLR 2.0.50727)"; …Run Code Online (Sandbox Code Playgroud)