我有一个,希望很小,问题。我需要能够直接发布到我的索引。现在我正在使用资源控制器:
Route::resource('appointments', 'AppointmentsController');
Run Code Online (Sandbox Code Playgroud)
而且我希望能够使用下拉列表从我的资源控制器更新我的索引视图以将值发布到我的索引。所以我可以像这样使用这些值:
public function index(Request $request)
Run Code Online (Sandbox Code Playgroud)
直到此时,我使用不同的路由来发布,然后重定向到我的约会.index 路由,依此类推。但那是愚蠢的。我希望仍然能够使用我的资源控制器,否则我需要创建很多路由(因为我使用了一堆资源控制器并且我需要能够直接发布到所有这些的索引)。
解决此问题的最有效方法是什么?我确实尝试使用 url 打开我的表单,然后在末尾添加一个斜杠,但这并没有奏效。
从服务器端,我需要终止/中止请求,而不像nginx 的 444那样对客户端做出任何响应。
从客户端看,它应该看起来像是由对等方重置的连接。
我刚开始学习 Python 并面临这个问题。Trued 从亚马逊解析价格并将其打印到控制台。
这是我的代码:
import requests, bs4
def getAmazonPrice(productUrl):
res = requests.get(productUrl)
res.raise_for_status()
soup = bs4.BeautifulSoup(res.text, 'html.parser')
elems = soup.select('#addToCart > a > h5 > div > div.a-column.a-span7.a-text-right.a-span-last > span.a-size-medium.a-color-price.header-price')
return elems[0].text.strip()
price = getAmazonPrice('http://www.amazon.com/Automate-Boring-Stuff-Python-Programming/dp/1593275994/ref=sr_1_2?ie=UTF8&qid=1460386052&sr=8-2&keywords=python+book')
print('The price is ' + price)
Run Code Online (Sandbox Code Playgroud)
错误信息:
回溯(最近一次调用):文件“D:/Code/Python/Basic/webBrowser-Module.py”,第 37 行,在 price = getAmazonPrice(' http://www.amazon.com/Automate-Boring-Stuff -Python-Programming/dp/1593275994/ref=sr_1_2?ie=UTF8&qid=1460386052&sr=8-2&keywords=python+book ') 文件“D:/Code/Python/Basic/webBrowser-Module.py”,第 30 行,在getAmazonPrice res.raise_for_status() 文件“C:\Python33\lib\requests\models.py”,第 844 行,在 raise_for_status 中引发 HTTPError(http_error_msg, response=self) requests.exceptions.HTTPError:503 服务器错误:服务不可用 url : http://www.amazon.com/Automate-Boring-Stuff-Python-Programming/dp/1593275994/ref=sr_1_2?ie=UTF8&qid=1460386052&sr=8-2&keywords=python+book
进程以退出代码 1 结束
我正在将我的一个项目从requestover切换到更轻量级的项目(例如 got、axios 或 fetch)。一切都进行得很顺利,但是,我在尝试上传文件流 (PUT和POST)时遇到了问题。它与请求包一起工作正常,但其他三个中的任何一个从服务器返回 500。
我知道 500 通常意味着服务器端的问题,但它仅与我正在测试的 HTTP 包一致。当我恢复我的代码以使用时request,它工作正常。
这是我当前的请求代码:
Request.put(`http://endpoint.com`, {
headers: {
Authorization: `Bearer ${account.token.access_token}`
},
formData: {
content: fs.createReadStream(localPath)
}
}, (err, response, body) => {
if (err) {
return callback(err);
}
return callback(null, body);
});
Run Code Online (Sandbox Code Playgroud)
这是使用另一个包的尝试之一(在这种情况下,得到了):
got.put(`http://endpoint.com`, {
headers: {
'Content-Type': 'multipart/form-data',
Authorization: `Bearer ${account.token.access_token}`,
},
body: {
content: fs.createReadStream(localPath)
}
})
.then(response => {
return callback(null, response.body);
})
.catch(err => {
return callback(err);
});
Run Code Online (Sandbox Code Playgroud)
根据获得的文档,我还尝试 …
我正在使用 Laravel 5.3。当我尝试提交表单时出现此错误。我使用了 laravelcollective/html。这是我的代码:
路线/ web.php
Route::resource('add-new-tenant', 'SuperAdmin\TenantController');
Route::resource('new-tenant', 'SuperAdmin\TenantController@store');
Run Code Online (Sandbox Code Playgroud)
控制器:
<?php
namespace App\Http\Controllers\SuperAdmin;
use App\Tenant;
use App\Http\Requests;
use App\Http\Requests\CreateTenantRequest;
use App\Http\Controllers\Controller;
class TenantController extends Controller
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
return view('pages.superadmin.add-new-tenant');
}
/**
* Store a newly created resource in storage.
*
* @param \App\Http\Requests\CreateTenantRequest $request
* @return \Illuminate\Http\Response
*/
public function store(CreateTenantRequest $request)
{
Tenant::create($request->all());
return redirect('add-new-tenant');
}
}
Run Code Online (Sandbox Code Playgroud)
我创建了一个验证表单的请求。代码如下:
应用程序/Http/Requests/CreateTenantRequest.php
<?php
namespace App\Http\Requests; …Run Code Online (Sandbox Code Playgroud) 晚上,我正在编写一个简单的 Objective-C 应用程序,作为对学校项目的请求。
我必须使用 Marvel API 来检索所有 Marvel Characters,全部。
但是在获取字符的 API 中有一种限制,一开始我认为字符列表有不同的页面,但我找不到任何参考。比我看到一个名为limit的查询参数:将结果集限制为指定数量的资源。
所以我决定尝试将限制参数设置为他的最大值 100,它有效,它得到 100 个字符。但是总共有1000个字符。
如果没有设置参数限制,我会得到 20 个字符。
这是我到目前为止所做的代码。我正在使用 AFNetworking 吊舱。Github 链接
请帮我弄清楚是从 Marvel API 请求所有 1000 多个字符的逻辑。
我正在使用 HttpClient 向 api 发出请求。此代码位于与两个附加项目(控制台和 Asp.Net Mvc 项目)共享的类库项目中。当我从控制台项目发出请求时,它工作得很好,但在 asp 项目中,它阻塞了行
using(Stream responseStream = await response.Content.ReadAsStreamAsync()
Run Code Online (Sandbox Code Playgroud)
这是我的请求代码
private async Task<dynamic> ReadJson(string url)
{
HttpResponseMessage response = await httpClient.GetAsync(url);
if (response.StatusCode == System.Net.HttpStatusCode.NoContent)
throw new RateLimitException();
if (response.StatusCode == System.Net.HttpStatusCode.Forbidden)
throw new AccessDeniedException();
if (response.StatusCode != System.Net.HttpStatusCode.OK)
throw new Exception("Error: " + response.StatusCode);
using (Stream responseStream = await response.Content.ReadAsStreamAsync())
using (StreamReader sr = new StreamReader(responseStream, System.Text.Encoding.UTF8))
{
string json = sr.ReadToEnd();
return JObject.Parse(json);
}
}
Run Code Online (Sandbox Code Playgroud)
我正在从控制台和 Asp.Net 项目对方法进行相同的调用。从控制台工作,但 asp .net 项目在读取响应内容时阻止行
api asp.net-mvc request console-application dotnet-httpclient
让 Django 有选择地/有条件地忽略请求(不返回任何内容)并断开连接(不阻止将来的请求)的最有效方法是什么?
我正在尝试制作一个XMLHttpRequest从外部文件加载 HTML 并将文件内容插入到div.
当我运行该函数时,它会在所有不够充分的正文中插入 HTML。
我的代码:
--------------------------> HTML <--------------------- -----
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script src="shit.js" charset="utf-8"></script>
<link rel="stylesheet" href="index.css">
<title>Test</title>
</head>
<body>
<button type="button" name="button" onclick="send()">Click me</button>
<div class="view" id="view"></div>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
--------------------------> CSS <--------------------- -----
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script src="shit.js" charset="utf-8"></script>
<link rel="stylesheet" href="index.css">
<title>Test</title>
</head>
<body>
<button type="button" name="button" onclick="send()">Click me</button>
<div class="view" id="view"></div>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
--------------------------> JS <--------------------- -----
.view {
margin-top: 5vh;
height: 15vh;
width: 80vw; …Run Code Online (Sandbox Code Playgroud) 我正在使用 nodeJS 代码使用请求模块进行休息调用。我也使用了回调函数,但请求函数没有被执行。
我的流程转到函数 searchTSTData 但请求方法没有被执行。
从回调函数中,我只得到 responseString = 'Yet to make query rest',我已在 searchTSTData 函数中对其进行了初始化。它不会根据 API 返回的响应进行更新,该响应应该是错误或成功响应字符串。
我已将模块包含在 zip 中,因为 lambda 不会抛出错误并通过测试。另外我确定请求模块不能像在 Cloudwatch 日志中那样工作我没有看到我在请求中写的任何 console.logs。
请建议我哪里出错了。我是 NodeJS 的新手。
这是代码 -
'use strict';
const request = require('request');
const Alexa = require('alexa-sdk');
const APP_ID = 'amzn1.ask.skill.80a49cf5-254c-123a-a456-98745asd21456';
const languageStrings = {
'en': {
translation: {
TST: [
'A year on Mercury is just 88 days long.',
],
SKILL_NAME: 'TEST',
GET_TST_MESSAGE: "Here's your TST: You searched for ",
HELP_MESSAGE: 'You can say get …Run Code Online (Sandbox Code Playgroud) request ×10
api ×2
node.js ×2
php ×2
ajax ×1
alexa ×1
asp.net-mvc ×1
aws-lambda ×1
axios ×1
controller ×1
django ×1
fetch ×1
go ×1
html ×1
ios ×1
javascript ×1
laravel ×1
laravel-5.3 ×1
networking ×1
no-response ×1
python ×1
resources ×1
validation ×1