我通常所做的是在带有隐藏字段的表单中进行的操作:
<input type="hidden" name="someName" value="someVal" />
Run Code Online (Sandbox Code Playgroud)
我已经能够通过一些简单的东西获得价值
$someVar = $_REQUEST['someVal'];
Run Code Online (Sandbox Code Playgroud)
但是现在我试图通过这样的方式发送 DOM 元素 id 中的所有值
<input type="hidden" name="someNewName" id="element_id_name" />
Run Code Online (Sandbox Code Playgroud)
我这样做正确吗?这甚至可以做到吗?还是我离题了?如何从最后一行中获取值?或者我如何以正确的方式将该数据发送到请求?
谢谢,亚历克斯
我在请求应用程序上执行了一个简单的Cheerio解析。不知道为什么在尝试设置数组时会出现这个未定义的错误,但是我猜该值不存在。
var $ = cheerio.load(body);
var json = [
{ "range": "", "address": "", "state": "", "zip": "", "info": "" }
];
$('.findCourse').each(function (i, elem) {
// Range Name
console.log("iteration - ", i);
console.log("name - ", $(this).text().trim());
json[i].range = $(this).text().trim();
});
Run Code Online (Sandbox Code Playgroud)
这是我的控制台响应,它读取并设置它在已抓取的html中找到的前两个项目。
iteration - 0
name - Pollock's Ferry Hunting Club Inc.
iteration - 1
name - Eagle 1
Run Code Online (Sandbox Code Playgroud)
TypeError:无法设置未定义的属性“范围”
Run Code Online (Sandbox Code Playgroud)at Object.<anonymous> (/usr/local/node_app/server.js:30:31) at exports.each (/usr/local/node_app/node_modules/cheerio/lib/api/traversing.js:267:24) at Request.request.post.form.__EVENTTARGET [as _callback] (/usr/local/node_app/server.js:26:30) at Request.self.callback (/usr/local/node_app/node_modules/request/request.js:121:22) at Request.EventEmitter.emit (events.js:98:17) at Request.<anonymous> (/usr/local/node_app/node_modules/request/request.js:978:14) …
我不明白我得到的这个错误.我曾多次尝试清理和构建我的项目.谁能帮我?Program.cs中
using System;
using System.Collections.Generic;
using System.Net.NetworkInformation;
using System.Net.Sockets;
using System.IO;
using System.Threading.Tasks;
namespace HTTPrequestApp
{
class Program
{
static void Main(string[] args)
{
var lstWebSites = new List<string>
{
"www.mearstransportation.com",
"www.amazon.com",
"www.ebay.com",
"www.att.com",
"www.verizon.com",
"www.sprint.com",
"www.centurylink.com",
"www.yahoo.com"
};
string filename = @"RequestLog.txt";
{
using (var writer = new StreamWriter(filename, true))
{
foreach (string website in lstWebSites)
{
for (var i = 0; i < 4; i++)
{
MyWebRequest request = new MyWebRequest();
request.Request(website);
}
}
}
}
}
} …Run Code Online (Sandbox Code Playgroud) 因此,如果用户未选择任何选项,我想获取所有项目,否则根据请求数据查询项目。但是我无法将传递$request给我的函数。这是我的代码:
public function showProducts(Request $request)
{
$products = Product::all();
if(count($request->all()) != 0) {
$products = Product::where(function($query) {
$minPrice = $request['min'] ? $request['min'] : null;
$maxPrice = $request['max'] ? $request['max'] : null;
$colors = $request['color'] ? $request['color'] : null;
$sizes = $request['size'] ? $request['size'] : null;
if($minPrice != null && $maxPrice != null) {
$query->where('price', '>=', $minPrice)->where('price', '<=', $maxPrice);
}
if($minPrice == null && $maxPrice == null && $colors == null && $sizes == null) {
}
})->get();
} …Run Code Online (Sandbox Code Playgroud) 我<Response [400]>在运行脚本时不断进入终端.
我试过了
import requests
import json
url = 'http://172.19.242.32:1234/vse/account'
data = '{
"account_id": 1008,
"email_address": "bhills_4984@mailinator.com",
"password": "qqq",
"account_type": "customer",
"name_prefix": "",
"first_name": "Beverly",
"middle_names": "",
"last_name": "Hills",
"name_suffix": "",
"non_person_name": false,
"DBA": "",
"display_name": "BeverlyHills",
"address1": "4984 Beverly Dr",
"address2": "4984 Beverly Dr",
"address3": "",
"city": "Beverly Hills",
"state": "CA",
"postal_code": "90210",
"nation_code": "90210",
"phone1": "3105554984",
"phone2": "",
"phone3": "",
"time_zone_offset_from_utc": -5,
"customer_type": "2",
"longitude": -118.4104684,
"latitude": 34.1030032,
"altitude": 0
}'
headers = {'content-type': 'application/json'}
r …Run Code Online (Sandbox Code Playgroud) 在我的应用程序中,当用户终止应用程序时,我需要向服务器发送一些指令。在applicationWillTerminate函数中,我尝试发送它,但是它从未发送到服务器。我尝试使用Alamofire和本机URLSession,但是它不起作用。有人知道我怎么发送吗?我用这个代码
let request = "\(requestPrefix)setDriverOrderStatus"
if let url = URL(string:request) {
var parameters : [String : String] = [:]
parameters["access_token"] = UserSession.accessToken
parameters["driver_id"] = UserSession.userID
parameters["status"] = status
var req = URLRequest(url: url)
req.httpMethod = HTTPMethod.put.rawValue
do {
req.httpBody = try JSONSerialization.data(withJSONObject: parameters, options: .prettyPrinted)
} catch let error {
print(error.localizedDescription)
}
_ = URLSession.shared.dataTask(with: req, completionHandler: { data, response, error in
guard error == nil else {
print(error ?? "error")
return
}
guard let data = data else { …Run Code Online (Sandbox Code Playgroud) 这是我的jsp:
<form method='post' action='/controller'>
<div >
<input class="form-control" type="text" id="name-input-field" pattern="[A-Z][a-z]+([ -][A-Z][a-z]+)*" required >
</div>
</form>
Run Code Online (Sandbox Code Playgroud)
这是我的servlet:
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
req.getParameter("name-input-field");//appears null
}
Run Code Online (Sandbox Code Playgroud)
请帮我找错.
在我的iOS应用程序中,我使用Alamofire 4并想要使用查询参数向后端发送请求.但是Alamofire转换了"?" 在url查询中的"%3F"(http:// blahblahblah/mobile-proxy/authorizations%3FphoneNumber = + 555555555&userID = agent),我从后端收到404错误.我读到了有关URLEncoding的内容,但是我找不到任何方法可以将它与URLRequest一起使用,因为我使用带有URLRequest的自定义路由器枚举文件.这是我的路由器文件的一部分:
func asURLRequest() throws -> URLRequest {
let url = try Router.baseUrl.asURL()
var urlRequest = URLRequest(url: url.appendingPathComponent(path))
urlRequest.httpMethod = method.rawValue
switch self {
case .authorizations:
urlRequest.setValue("application/json", forHTTPHeaderField: "Content-Type")
urlRequest.setValue(getHeaderCredentials().operationID, forHTTPHeaderField: Constants.operationID)
urlRequest.setValue(getHeaderCredentials().appCode, forHTTPHeaderField: Constants.appCode)
case .startAuthentication, .startContractOperation:
urlRequest.setValue("application/json", forHTTPHeaderField: "Content-Type")
urlRequest.setValue(getHeaderCredentials().appCode, forHTTPHeaderField: Constants.appCode)
case .operationAllowance:
urlRequest.setValue("application/json", forHTTPHeaderField: "Content-Type")
default:
break
}
switch self {
case .authorizations:
urlRequest = try Alamofire.URLEncoding.queryString.encode(urlRequest, with: nil)
default:
break
}
return urlRequest
}
Run Code Online (Sandbox Code Playgroud)
我尝试Alamofire.URLEncoding.queryString.encode,但它不起作用.
我的NodeJS / Koa.js应用出现一个奇怪的问题,我正在发出的HTTP请求返回此错误消息:
{"Message":"The request entity's media type 'application/x-www-form-urlencoded' is not supported for this resource."
Run Code Online (Sandbox Code Playgroud)
现在,当我使用邮递员发出相同的请求时,我会得到正确的结果,因此我推断出我的代码有问题。我似乎无法弄清楚。这是我发出请求和有效负载的代码。
// Content Type
if(options.contentType === 'json') {
headers['Content-Type'] = 'application/json';
}
// Content Length
if(options.contentLength) {
reqHeaders['Content-Length'] = options.contentLength
}
if(headers) {
for(let key in headers) {
if(!headers.hasOwnProperty(key)) {
continue;
}
reqHeaders[key] = headers[key];
}
}
const payload = {
headers : reqHeaders,
url : url,
method : requestType,
timeout : 10000,
form : vars,
followRedirect: true,
maxRedirects: 10,
body : '' || options.body …Run Code Online (Sandbox Code Playgroud) 在laravel我们怎么能做这样的事情?例如,如果我们写dd($ request); 在控制器中:
"slug_en" => "english_slug_here"
"lang_en" => "english"
"slug_es" => "spanish_slug_here"
"lang_es" => "spanish"
Run Code Online (Sandbox Code Playgroud)
如果我必须使用"英语",我只需要使用$ request-> lang_en; 但是,如果我只知道"英语"并想知道输入名称怎么办?
$request->X = "english";
Run Code Online (Sandbox Code Playgroud)
我想在这里X.我需要动态设置语言系统,但我卡在这里.如果有人可以帮助我,我会很高兴.提前致谢.