我正在创建一个 DataAnnotation,如果不成功将返回一个 BadRequest。
context.Result = new BadRequestResult();
Run Code Online (Sandbox Code Playgroud)
这很好用。
我想在其中包含一条消息,但 BadRequestResult 似乎没有接受任何消息参数?
有没有办法做到这一点......包括一条消息,例如“未提供参考号”
谢谢
我刚刚安装了Node.js,也许我错过了一些东西,但我正在尝试一个简单的http.request,只得到400个响应.我已经尝试了几个没有运气的主机.我从他们的站点安装了Node,这不起作用,所以我通过Homebrew卸载并安装并得到"400"的相同输出.我特别想知道我的Mac上是否需要更改以允许Node发送请求.
OSX 10.8.4节点0.10.13 Homebrew 0.9.4
var http = require("http");
var req = http.request({
host: "http://google.com"
}, function(res){
if (res.statusCode === 200) console.log(res);
else console.log(res.statusCode);
});
req.on("error", function(err){
console.log(err);
});
req.end();
Run Code Online (Sandbox Code Playgroud)
我感谢任何帮助.谢谢!
我已经设置了Review Board,从localhost访问它时工作正常.当我尝试通过ip(从LAN)访问它时,我得到了不好的请求.
我已将apache-wsgi.conf复制到我的apache conf目录中.
Apache的wsgi.conf
<VirtualHost *:8088>
ServerName localhost
DocumentRoot "/var/www/reviews.als.kz/htdocs"
# Error handlers
ErrorDocument 500 /errordocs/500.html
WSGIPassAuthorization On
WSGIScriptAlias "/reviews" "/var/www/reviews.als.kz/htdocs/reviewboard.wsgi/reviews"
<Directory "/var/www/reviews.als.kz/htdocs">
AllowOverride All
Options -Indexes +FollowSymLinks
Require all granted
</Directory>
# Prevent the server from processing or allowing the rendering of
# certain file types.
<Location "/reviews/media/uploaded">
SetHandler None
Options None
AddType text/plain .html .htm .shtml .php .php3 .php4 .php5 .phps .asp
AddType text/plain .pl .py .fcgi .cgi .phtml .phtm .pht .jsp .sh .rb
<IfModule mod_php5.c>
php_flag …Run Code Online (Sandbox Code Playgroud) 我想使用 JSON 数据(提供 JSON 作为 JsonObject)在 Retrofit 中调用 POST 方法(Magento REST API)。为此,我从邮递员那里打电话给我,对我来说工作正常。
我已经完成了 android 部分如下,
API接口
public interface APIService {
@POST("seq/restapi/checkpassword")
@Headers({
"Content-Type: application/json;charset=utf-8",
"Accept: application/json;charset=utf-8",
"Cache-Control: max-age=640000"
})
Call<Post> savePost(
@Body JSONObject jsonObject
);}
Run Code Online (Sandbox Code Playgroud)
APIUtility 类为
public class ApiUtils {
private ApiUtils() {
}
public static final String BASE_URL = "http://xx.xxxx.xxx.xxx/api/rest/";
public static APIService getAPIService() {
return RetrofitClient.getClient(BASE_URL).create(APIService.class);
}
Run Code Online (Sandbox Code Playgroud)
}
RetrofitClient 类为
private static Retrofit retrofit = null;
public static Retrofit getClient(String baseUrl) {
if (retrofit==null) {
retrofit = …Run Code Online (Sandbox Code Playgroud) 在下面的方法中有两个参数childFile和file,我通过邮递员运行此调用,但当我检查日志时它给出 400 Bad Request 错误,它说参数childFile不存在,我附上代码、错误和邮递员屏幕截图请告诉我什么是问题
控制器
@Transactional
@RequestMapping(method = RequestMethod.POST, value = "api/addchild",produces="application/json")
public ResponseEntity<?> child(Authentication authentication,
@RequestParam(value="childFile") String childFile, @RequestParam(value="file") MultipartFile file) {
ObjectMapper mapper = new ObjectMapper();
Child child;
try {
child=mapper.readValue(childFile, Child.class);
Child createdChild=childRepo.save(child);
if(createdChild!=null)
{
childService.createChildPhoto(file, createdChild.getId());
}
return ResponseEntity.ok("child created");
} catch (IOException e1) {
e1.printStackTrace();
}
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("Child can not be created , please check your headers and string body again.");
}
Run Code Online (Sandbox Code Playgroud)
日志
Content-Disposition: form-data; name] with value …Run Code Online (Sandbox Code Playgroud) 我正在创建一个新SearchNeighborhood对象并将其连接到请求中已经创建的SearchCity对象POST。
我有以下型号
class SearchCity(models.Model):
city = models.CharField(max_length=200)
class SearchNeighborhood(models.Model):
city = models.ForeignKey(SearchCity, on_delete=models.CASCADE)
neighborhood = models.CharField(max_length=200)
Run Code Online (Sandbox Code Playgroud)
我的相关序列化程序是:
class SearchNeighborhoodSerializer(serializers.ModelSerializer):
class Meta:
model = SearchNeighborhood
fields = ('pk', 'neighborhood')
Run Code Online (Sandbox Code Playgroud)
我的观点和相关方法是:
class CityNeighborhoodsListCreate(APIView):
def post(self, request, *args, **kwargs):
citypk = kwargs.get('citypk', None)
city=get_object_or_404(SearchCity,pk=citypk)
serialized = SearchNeighborhoodSerializer(data=request.data)
if serialized.is_valid(raise_exception=True):
validatedData = serialized.validated_data
neighborhood = validatedData.get('neighborhood')
neighborhoodobject = SearchNeighborhood(neighborhood= neighborhood, city = city)
neighborhoodobject.save()
createdneighborhood = SearchNeighborhoodSerializer(neighborhoodobject)
return Response({
'neighborhood': createdneighborhood.data
})
Run Code Online (Sandbox Code Playgroud)
我正在使用 Angular 4
我的AJAX要求是: …
post bad-request deserialization django-rest-framework angular
一年多以来,我一直在为 google 数据流构建和创建模板。我从来没有遇到过创建模板并通过options.setTemplateLocation(templatePath);调用将它们上传到 gcs 的问题。从今天开始,Pipeline.create(options);在 eclipse 中使用 java 程序创建管道并运行 java 程序时,出现以下异常:
Exception in thread "main" java.lang.RuntimeException: Failed to construct instance from factory method DataflowRunner#fromOptions(interface org.apache.beam.sdk.options.PipelineOptions)
at org.apache.beam.sdk.util.InstanceBuilder.buildFromMethod(InstanceBuilder.java:233)
at org.apache.beam.sdk.util.InstanceBuilder.build(InstanceBuilder.java:162)
at org.apache.beam.sdk.PipelineRunner.fromOptions(PipelineRunner.java:52)
at org.apache.beam.sdk.Pipeline.create(Pipeline.java:142)
at mypackage.PipelineCreation.getTemplatePipeline(PipelineCreation.java:34)
at myotherpackage.Main.main(Main.java:51)
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.apache.beam.sdk.util.InstanceBuilder.buildFromMethod(InstanceBuilder.java:222)
... 5 more
Caused by: java.lang.RuntimeException: Unable to verify that GCS bucket gs://my-projects-staging-bucket exists.
at org.apache.beam.sdk.extensions.gcp.storage.GcsPathValidator.verifyPathIsAccessible(GcsPathValidator.java:92)
at org.apache.beam.sdk.extensions.gcp.storage.GcsPathValidator.validateOutputFilePrefixSupported(GcsPathValidator.java:61)
at org.apache.beam.runners.dataflow.DataflowRunner.fromOptions(DataflowRunner.java:228)
... 10 more
Caused by: …Run Code Online (Sandbox Code Playgroud) bad-request google-authentication google-cloud-storage google-cloud-dataflow
我使用的是 Tomcat 7.0.54.0。
我的应用程序中有一个使用该GET方法的 REST API。在此 API 的 URI 中,有一个斜杠字符 ( /),我在调用 API 之前对其进行编码。那个例子:http://192.168.168.168:38080/myApp/getDetails/test%2Fstring。
URI 参数中的实际字符串是test/string。在调用 API 之前,我使用URLEncoder.encode("test/string", "UTF-8"),这给了我test%2Fstring. 与我在 URL 中使用的相同。
此 API 调用在一种环境中工作正常,但在其他环境中会出现错误HTTP 400 (Bad request)。
两台服务器的Java版本、Tomcat版本、操作系统环境(Linux)和版本都相同。在 中server.xml,我像这样配置了连接器端口:
<Connector URIEncoding="UTF-8" connectionTimeout="20000" port="38080" protocol="HTTP/1.1" redirectPort="8443"/>
Run Code Online (Sandbox Code Playgroud)
另外,还有一个字符编码过滤器,配置如下代码:
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException
{
HttpServletRequest httpRequest = null;
HttpServletResponse httpResponse = null;
if (request instanceof HttpServletRequest)
{
httpRequest = …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用 Jira REST API 包含组件来创建问题。我正在发布此 JSON,但我得到远程服务器返回错误:(400) 错误请求。
问题是:-没有组件就没有错误,但是当组件有问题时。有什么帮助吗?JSON:
{
"fields": {
"project": {
"key": "keyGoesHere"
},
"assignee": {
"name": "name.surname"
},
"component": {
"name": "someName"
},
"summary": "test2",
"description": "test2",
"issuetype": {
"name": "Task"
}
}
}
Run Code Online (Sandbox Code Playgroud) 我正在开发一款 Flask 应用程序,最近将其转换为只有一个应用程序的简单蓝图模板。在调试模式下(FLASK_DEBUG=1)它工作正常,但是当它不处于调试模式时,无论我尝试点击哪个页面,我都会收到“HTTPStatus.BAD_REQUEST - 代码 400”。它会自动点击https://127.0.0.1:5000,所以我尝试执行http://127.0.0.1:5000但这也不起作用,因为它似乎重定向回 https 。
应用程序.py
from app import create_app
application = app = create_app()
if __name__ == "__main__":
application.run()
Run Code Online (Sandbox Code Playgroud)
routes.py(为了简洁起见,仅包含索引路由并省略导入)
app_blueprint = Blueprint('app_blueprint', __name__, template_folder='app/templates', static_folder='static')
@app_blueprint.route('/')
@app_blueprint.route('/index')
def index():
return render_template('app_blueprint/index.html', title='Home')
Run Code Online (Sandbox Code Playgroud)
从应用程序内初始化.py。我的 csp 很乱,因为我正在尝试看看这是否导致了问题。
migrate = Migrate()
login = LoginManager()
login.login_view = 'login'
mail = Mail()
moment = Moment()
talisman = Talisman()
def create_app(config_class=Config):
application = Flask(__name__)
application.config.from_object(config_class)
from app.models import db
db.init_app(application)
migrate.init_app(application, db)
login.init_app(application)
mail.init_app(application)
moment.init_app(application) …Run Code Online (Sandbox Code Playgroud) 我正在尝试网页抓,这是我的代码.
出于某种原因,我收到HTTP错误400:错误的请求,我从来没有这样做过.
有任何想法吗?
这是我的代码:
import urllib.request
import re
url = ('https://www.myvue.com/whats-on')
req = urllib.request.Request(url, headers={'User Agent': 'Mozilla/5.0'})
def main():
html_page = urllib.request.urlopen(req).read()
content=html_page.decode(errors='ignore', encoding='utf-8')
headings = re.findall('<th scope="col" abbr="(.*?)">', content)
print(headings)
main()
Run Code Online (Sandbox Code Playgroud) 长话短说:我正在创建应该100%REST的API。我试图覆盖以下情况的默认响应:我的@RestController中有一个方法,该方法具有@RequestBody作为属性
@RequestMapping(value = {"register"}, method = RequestMethod.POST, produces = "application/hal+json")
public Resource<User> registerClient(@RequestBody User user, HttpServletRequest request)
Run Code Online (Sandbox Code Playgroud)
如果我发送适当的请求,该方法就可以正常工作。但是,如果我不这样做,就会有问题。当请求的主体为空时,我得到一个状态为400的通用Tomcat错误页面,我需要它仅发送字符串或JSON对象。
到目前为止,我试图在RestControllerAdvice中为org.springframework.web.binding包中的所有Spring异常添加异常处理程序,但是它也不起作用。
我已经知道,对于某些与安全性相关的错误,必须在配置中创建处理程序,但是我不知道是否是这种情况。
有没有人遇到类似的问题?有什么我想念的吗?
bad-request ×12
java ×2
post ×2
python ×2
spring ×2
android ×1
angular ×1
apache ×1
api ×1
c# ×1
components ×1
flask ×1
ip-address ×1
jira ×1
magento ×1
node.js ×1
python-3.x ×1
retrofit2 ×1
review-board ×1
spring-boot ×1
spring-mvc ×1
tomcat ×1
utf-8 ×1