我需要让表单发送POST和GET请求(由于IE和iframe中的一些错误),你怎么能这样做?
发送的数据不是很安全,所以如果可以通过GET设置它并不重要,只需要确保它是双向设置的.
谢谢您的帮助!
我能够对参数字符串进行POST.我使用以下代码:
String parameters = "firstname=john&lastname=doe";
URL url = new URL("http://www.mywebsite.com");
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setDoOutput(true);
connection.setRequestProperty("Content-Type","application/x-www-form-urlencoded");
connection.setRequestMethod("POST");
OutputStreamWriter out = new OutputStreamWriter(connection.getOutputStream());
out.write(parameters);
out.flush();
out.close();
connection.disconnect();
Run Code Online (Sandbox Code Playgroud)
但是,我需要对二进制数据进行POST(以byte []的形式).
不知道如何更改上面的代码来实现它.
有人可以帮我这个吗?
我需要通过POST点击a在新窗口中打开一个JSF页面<h:commandButton>.我知道我可以使用JavaScript实现这一点.但我想使用JSF而不是JavaScript来实现这个目标.
我怎样才能做到这一点?我正在使用JSF 2.0.
我在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) 我有一个带有文本框的表单,该文本框将数据发布到使用"htmlentities"功能的php文件,以便通过电子邮件发送给网站所有者.
问题是有人设法在文本中获得超链接,而htmlentities()不会删除它.
这是我的文本框html:
<input name="usertext" type="text" />
Run Code Online (Sandbox Code Playgroud)
这是接收后的数据(我离开了电子邮件的代码,因为这是没问题的.我改变它只是呼应了接收到的数据,所以我可以尝试复制黑客做了什么.如果我知道他是如何做到的我的PHP代码,我可以找到阻止它发生的方法):
echo trim(htmlentities($_POST["usertext"], ENT_QUOTES));
Run Code Online (Sandbox Code Playgroud)
现在黑客发送了一些数据,这就是结果html(源代码 - 这意味着它在浏览器中显示了一个正常的链接):
<a target="_blank" href="mailto:nyjfvw@fbjgzy.com">nyjfvw@fbjgzy.com</a>
Run Code Online (Sandbox Code Playgroud)
我认为htmlentities()总能阻止任何人输入任何类型的HTML.如果我输入一个超链接,例如:
<a href="aaa" />
Run Code Online (Sandbox Code Playgroud)
我明白了:
<a href="aaa" />
Run Code Online (Sandbox Code Playgroud)
但是黑客的文本并没有这样编码.
所以我的问题是:
我做了一些研究,黑客可能会用utf-7或其他东西编码他的文本?
我已收到几封带有相同链接的电子邮件.这个黑客显然正在测试我的网站,看看他是否可以做XSS或其他什么.
我有一个表单,它有一个upload($_FILES['watch_photo'])字段.
我环顾四周,把这个功能放在一起.
它基本上获取所有相关信息,以便将来可以重复使用,它将在完成后返回$ pid和文件URL的数组.
问题是ACF没有提供太多信息,如何使用http://www.advancedcustomfields.com/resources/functions/update_field/将图像添加到其字段中update_field()
function my_update_attachment($f,$pid,$t='',$c='') {
wp_update_attachment_metadata( $pid, $f );
if( !empty( $_FILES[$f]['name'] )) { //New upload
require_once( ABSPATH . 'wp-admin/includes/file.php' );
$override['action'] = 'editpost';
$file = wp_handle_upload( $_FILES[$f], $override );
if ( isset( $file['error'] )) {
return new WP_Error( 'upload_error', $file['error'] );
}
$file_type = wp_check_filetype($_FILES[$f]['name'], array(
'jpg|jpeg' => 'image/jpeg',
'gif' => 'image/gif',
'png' => 'image/png',
));
if ($file_type['type']) {
$name_parts = pathinfo( $file['file'] );
$name = $file['filename'];
$type = $file['type'];
$title …Run Code Online (Sandbox Code Playgroud) 我正在寻找一种方法来从控制器发出一个发布请求到外部网址.发布的数据是一个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的答案.谢谢.
我正在使用jquery将Json数据发布到服务器.但是,当我发布如下的帖子请求时,
$.ajax({
type : 'POST' ,
url : uri,
data : jsonStrJson,
contentType : 'application/json',
success : successFunction
});
Run Code Online (Sandbox Code Playgroud)
即使我发布了一个json对象,http请求头内容类型也不是"application/json".
由于它不是applcation/json,服务器不处理requset并返回415.
有没有办法使用javascript或jquery API设置标头?
我需要发布JSONObject(使用Volley)一个以JSONArray格式返回响应的Web服务.
这是我到目前为止所尝试的.
final JSONObject requestJsonObject = new JSONObject();
requestJsonObject.put("username", userName);
requestJsonObject.put("password", password);
JsonObjectRequest jsonObjReq = new JsonObjectRequest(Method.POST, ServiceUrls.LOGIN_URL, requestJsonObject, loginResponseListener, loginErrorListener);
private Listener<JSONObject> loginResponseListener = new Listener<JSONObject>() {
@Override
public void onResponse(JSONObject resposne) {
//other stuff goes here
}
};
Run Code Online (Sandbox Code Playgroud)
但我JSONException要说的是JSONArray无法转换为JSONObject.有没有办法以JSONArray格式获得响应?什么是我的问题的最佳解决方案?JSONObject如果我使用StringRequest而不是,我该如何发送JsonObjectRequest?请指导我
我创建了一个将http post请求发送到另一台服务器的java应用程序.
该应用程序在C盘中的PC上完美运行.
应用程序一词完美在PC上与本地映射驱动器.
但是当我将我的应用程序放入网络映射驱动器时,我收到一个错误:
java.net.SocketException:无效参数:在映射驱动器中创建
这是我的代码
HttpClient httpClient = HttpClientBuilder.create().build();
HttpPost postRequest = new HttpPost(getUrl());
postRequest.setHeader(AUTHERIZTION, getAuthString());
HttpResponse response = httpClient.execute(postRequest);
Run Code Online (Sandbox Code Playgroud)
这是完整的错误:
java.net.SocketException:无效参数:
在java.net.Socket.getImpl(未知源)创建java.net.Socket.createImpl(未知源)
, 位于org.apache的
java.net.Socket.setSoTimeout(未知源)
.http.impl.conn.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientCo nnectionOperator.java:119)
在org.apache.http.impl.conn.PoolingHttpClientConnectionManager.connect(PoolingHttpClientCon nectionManager.java:353)
在org.apache.http.impl.execchain .MainClientExec.establishRoute(MainClientExec.java:380)
org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:236)
org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java) :184)
在org.apache的org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:88)
org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:110)
. http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:184)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:82)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:107)atg.apache.http.impl.client.CloseableHttpClient.execute
(CloseableHttpClient.java:55)
at rest.RestClient.postGetQuery(RestClient) .java:105)
at Main.Smain
(Main.java:21)的Main.runAction(Main.java:63)
中的frame.ScanJFrame.initProperty(ScanJFrame.java:195)
我试过这个:
setx _JAVA_OPTIONS -Djava.net.preferIPv4Stack=true
Run Code Online (Sandbox Code Playgroud)
但没有改变.
我能做什么?
tnx很多