我正在使用 YouTube 数据 API。我确实设置了参数,但是从开发人员工具打开网络时,它显示错误:“必需参数:部分”
axios 代码-
import axios from 'axios';
const KEY='[my key]'
export default axios.create({
baseURL:'https://www.googleapis.com/youtube/v3',
params:
{
part:'snippet',
maxResults:5,
key: KEY
}
})
Run Code Online (Sandbox Code Playgroud)
发送 API 请求的回调函数
termSearch= (term)=>
{
console.log(term)
youtube.get('/search',{
params:
{
q:term
}
})
Run Code Online (Sandbox Code Playgroud)
我希望收到 JSON 响应,但控制台显示 - Error:GET https://www.googleapis.com/youtube/v3/search?q=asdas 400
PayPal 沙盒测试不断出现以下错误:
http 400 - 错误请求 您的浏览器发送了该服务器无法理解的请求。
我正在使用 PayPal 提供的 git 示例代码,但无法解决此错误。
代码 [PayPalIPN.php]
<?php
class PaypalIPN
{
/** @var bool Indicates if the sandbox endpoint is used. */
private $use_sandbox = false;
/** @var bool Indicates if the local certificates are used. */
private $use_local_certs = true;
/** Production Postback URL */
const VERIFY_URI = 'https://ipnpb.paypal.com/cgi-bin/webscr';
/** Sandbox Postback URL */
const SANDBOX_VERIFY_URI = 'https://ipnpb.sandbox.paypal.com/cgi-bin/webscr';
/** Response from PayPal indicating validation was successful */
const VALID = 'VERIFIED';
/** …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用 HttpClient 对 Web API 方法发出 PUT 请求。几乎相同的 POST 请求按预期工作,但 PUT 请求会导致 400(错误请求)错误。我不确定我做错了什么。
这是我的 Web API 控制器代码:
public HttpResponseMessage Post(object val)
{
Debug.WriteLine(val.ToString());
return new HttpResponseMessage(HttpStatusCode.OK);
}
public HttpResponseMessage Put(int id, object val)
{
Debug.WriteLine(id.ToString(), val.ToString());
return new HttpResponseMessage(HttpStatusCode.OK);
}
Run Code Online (Sandbox Code Playgroud)
这是尝试调用这些方法的客户端代码。POST 请求如下所示:
var client = new HttpClient();
var content = log.ToJsonContent();
var address = new Uri(_webApiBaseAddress + "logs");
client.PostAsync(address, content).ContinueWith(requestTask =>
{
requestTask.Result.EnsureSuccessStatusCode();
});
Run Code Online (Sandbox Code Playgroud)
不起作用的 PUT 请求如下所示:
var client = new HttpClient();
var content = log.ToJsonContent();
var address = new …Run Code Online (Sandbox Code Playgroud) c# restsharp http-status-code-400 asp.net-web-api dotnet-httpclient
我是Jax-RS的新手。我正在尝试使用Jersey实现一个简单的GET方法。我正在获得Collection资源的正确输出,但是实例资源却出现“ ERROR 400 Bad Request”。我被困在这一点上。一切似乎都是正确的,但我缺少一些我无法弄清的东西。我已经尝试了最近10天。任何帮助将是可观的。请在下面找到我的代码。我使用的是POSTMAN rest客户端,它抛出“意外的'T'”作为响应,而ARC则抛出“请求实体不能为空”。并且都是错误400错误的请求。
这是我的web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
id="WebApp_ID" version="3.1">
<display-name>MessangerWithoutMaven</display-name>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>Jersey Web Application</servlet-name>
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>jersey.config.server.provider.packages</param-name>
<param-value>com.manish.jax_rs.Messanger</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Jersey Web Application</servlet-name>
<url-pattern>/webapi/*</url-pattern>
</servlet-mapping>
</web-app>
Run Code Online (Sandbox Code Playgroud)
这是我的MessageResource.java:
package com.manish.jax_rs.Messanger.resources;
import java.util.List;
import javax.websocket.server.PathParam;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import com.manish.jax_rs.Messanger.model.Message;
import com.manish.jax_rs.Messanger.service.MessageService;
@Path("/messages")
public class MessageResource {
MessageService messageService = new MessageService();
@GET
@Produces(MediaType.APPLICATION_JSON)
public List<Message> getMessages(){
return …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) 我有一个 Groovy 脚本,它使用 URLConnection 来处理 GET 请求(在本例中是为了获取身份验证令牌);
URLConnection loginURI = new URL("www.myaddress.fish").openConnection();
loginURI.setRequestProperty("Authorization","me:you");
response = loginURI.getInputStream();
Run Code Online (Sandbox Code Playgroud)
没什么复杂的,当响应为 200 或类似值时,此代码可以正常工作。回复包含我需要取得进展的详细信息。
但是,有时响应是 4xx 响应(最常见的是来自无效授权标头的 400 Bad Request),并且通过 SOAPUI 或类似的方式运行相同的请求,我可以看到响应正文包含有用的信息(例如“您的用户名不正确”) ')。我希望能够捕获有用的信息进行处理,但我不知道该怎么做。
我尝试过传统的“try/catch”想法,但我得到的是 Java 异常而不是响应正文。我愚蠢地尝试了沼泽标准
println response.text
Run Code Online (Sandbox Code Playgroud)
在 catch 部分,但这根本不起作用。假设响应正文存储在某处,我如何读取它?
是否可以从 Asp.Net Core 3.1 Web Api 返回自定义错误消息给客户端?我尝试了几种不同的方法来设置“ReasonPhrase”,但没有成功。我尝试过使用StatusCode:
return StatusCode(406, "Employee already exists");
Run Code Online (Sandbox Code Playgroud)
我尝试使用 HttpResponseMessage 返回:
HttpResponseMessage msg = new HttpResponseMessage();
msg.StatusCode = HttpStatusCode.NotAcceptable;
msg.ReasonPhrase = "Employee alredy exists";
return (IActionResult)msg;
Run Code Online (Sandbox Code Playgroud)
我试图向客户端返回一条消息,调用该员工已存在的方法:
public async Task<IActionResult> CreateEmployee([FromBody] EmployeeImport Employee)
{
var exists = await employeeService.CheckForExistingEmployee(Employee);
if (exists > 0)
{
//return StatusCode(406, "Employee already exists");
HttpResponseMessage msg = new HttpResponseMessage();
msg.StatusCode = HttpStatusCode.NotAcceptable;
msg.ReasonPhrase = "Employee already exists";
return (IActionResult)msg;
}
}
Run Code Online (Sandbox Code Playgroud)
这是客户端中的代码:
public async Task<ActionResult>AddEmployee(EmployeeImport employee)
{
var message …Run Code Online (Sandbox Code Playgroud) http-status-codes http-status-code-400 asp.net-core asp.net-core-webapi
当我向服务器发送POST请求时,如果响应为200,我将获得JSON正文.但是对于不成功的请求,服务器发送400响应代码但我的android代码抛出FileNotFoundException.阅读400响应和200响应之间有什么区别吗?
StringBuffer responseBuilder = new StringBuffer();
String line = null;
HttpURLConnection conn = null;
OutputStream out = null;
BufferedReader rd = null;
System.setProperty("http.keepAlive", "false");
try
{
conn = (HttpURLConnection) new URL(requestURL).openConnection();
conn.setRequestMethod("POST");
conn.setDoOutput(true);
conn.setDoInput(true);
conn.setUseCaches(false);
conn.setAllowUserInteraction(false);
conn.setConnectTimeout(NetworkConstants.CONNECTION_TIMEOUT);
conn.setReadTimeout(NetworkConstants.SOCKET_TIMEOUT);
out = conn.getOutputStream();
Writer writer = new OutputStreamWriter(out, "UTF-8");
String s = formatParams();
Log.d("-------------------------------------------------->", s);
writer.write(s);
writer.flush();
writer.close();
}
catch (Exception e)
{
}
finally
{
if (out != null)
{
try
{
out.close();
}
catch (IOException e)
{
e.printStackTrace();
}
} …Run Code Online (Sandbox Code Playgroud) 我正在尝试在 CentOS 7.5.1804 版本上为 Apache 2.4.6 配置 mod_evasive。我干净安装了 CentOS,干净安装了 Apache,没有提供任何页面或任何内容(只是示例 index.html 说你好世界),并且我使用本教程安装了 mod_evasive:https: //www.digitalocean.com/community/tutorials /如何使用-mod_evasive-for-apache-on-centos-7 来防护 dos 和 ddos
一切工作正常,除非我必须运行测试脚本,该脚本应该向服务器发送请求并由于 mod_evasive 而收到 403 错误。相反,我收到 400 Bad Request。
我将防火墙切换为 IPtables,并且打开了端口 80,事实上,示例页面在浏览器中工作正常。此外,SELinux 模式设置为宽容模式。
有什么建议么?
我正在尝试在 flutter 中向http://www.dneonline.com/calculator.asmx发送肥皂请求以添加 2 个数字
ElevatedButton(
onPressed: () async {
var request="""
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<Add xmlns="http://tempuri.org/">
<intA>1</intA>
<intB>2</intB>
</Add>
</soap:Body>
</soap:Envelope>
""";
http.Response response =
await http.post(
Uri.parse('http://www.dneonline.com/calculator.asmx'),
headers: {
"Content-Type": "text/xml; charset=utf-8",
"Host": "www.dneonline.com",
"Content-Length": request.length.toString(),
"SOAPAction": "http://tempuri.org/Add"
},
body: request
);
print(response.body);
},
child: new Text("Calculate"),
)
Run Code Online (Sandbox Code Playgroud)
但我收到错误
错误:XMLHttpRequest 错误。
C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/_internal/js_dev_runtime/patch/core_patch.dart 910:28 get current
Run Code Online (Sandbox Code Playgroud)
包/http/src/browser_client.dart 69:22
C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/zone.dart 1685:54 runUnary
C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/future_impl.dart 159:18 handleValue
C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/future_impl.dart 766:44 handleValueCallback
C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/future_impl.dart 795:13 _propagateToListeners C:/b/s/w/ir/cache/builder /src/out/host_debug/dart-sdk/lib/async/future_impl.dart 592:7 …
java ×2
android ×1
apache ×1
asp.net-core ×1
axios ×1
bad-request ×1
c# ×1
flutter ×1
groovy ×1
httpresponse ×1
java-ee ×1
jax-rs ×1
jersey ×1
mod-evasive ×1
paypal ×1
paypal-ipn ×1
php ×1
post ×1
reactjs ×1
restsharp ×1
soap ×1
spring ×1
spring-boot ×1
web-services ×1