简而言之,我有一个网站,您可以在其中注册为用户并添加数据。目前只添加一次特定数据才有意义,因此添加应该是幂等的,但理论上您可以多次添加相同的数据。我不会在这里讨论。
根据RFC 2616,GET 请求应该是幂等的(真的是无效的)。我希望用户能够执行诸如访问之类的操作
http://example.com/<username>/add/?data=1
Run Code Online (Sandbox Code Playgroud)
这将添加该数据。让 PUT 请求使用 REST 来执行此操作是有意义的,但我不知道如何使用浏览器发出 PUT 请求,而且我非常怀疑大多数人是否愿意或愿意打扰。即使使用 POST 也是合适的,但这也有类似的问题。
是否有一些技术上正确的方法允许用户仅使用 GET 添加数据(例如,通过手动访问链接,或允许外部网站使用链接)。当他们访问此页面时,我可以使用 javascript 或 cURL 发出自己的 POST/PUT 请求,但这似乎仍然违反了幂等 GET 请求的精神。
目标
如何使用Julia-lang从HTTP URL读取JSON?
我是Kotlin和 的新手Retrofit。我想打电话给基地URL通过Retrofit和打印的原始JSON响应。什么是最简单的最小配置?
让我们说,
base url = "https://devapis.gov/services/argonaut/v0/"
method = "GET"
resource = "Patient"
param = "id"
Run Code Online (Sandbox Code Playgroud)
我试过,
val patientInfoUrl = "https://devapis.gov/services/argonaut/v0/"
val infoInterceptor = Interceptor { chain ->
val newUrl = chain.request().url()
.newBuilder()
.query(accountId)
.build()
val newRequest = chain.request()
.newBuilder()
.url(newUrl)
.header("Authorization",accountInfo.tokenType + " " + accountInfo.accessToken)
.header("Accept", "application/json")
.build()
chain.proceed(newRequest)
}
val infoClient = OkHttpClient().newBuilder()
.addInterceptor(infoInterceptor)
.build()
val retrofit = Retrofit.Builder()
.baseUrl(patientInfoUrl)
.client(infoClient)
.addConverterFactory(GsonConverterFactory.create())
.build()
Logger.i(TAG, "Calling retrofit.create")
try …Run Code Online (Sandbox Code Playgroud) 我正在尝试发出一个简单的 GET 请求:
https://www.google.com/search?q=stuff
Run Code Online (Sandbox Code Playgroud)
我使用过 Apache Http Lybrary:
import java.io.IOException;
import org.apache.http.Header;
import org.apache.http.HttpEntity;
import org.apache.http.HttpHeaders;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
public class INRIX {
private final CloseableHttpClient httpClient = HttpClients.createDefault();
public static void main(String[] args) {
INRIX inrix = new INRIX();
try {
inrix.peticionGet();
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
inrix.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
private void close() throws IOException {
httpClient.close(); …Run Code Online (Sandbox Code Playgroud) 下面的示例演示了使用 OpenFeign 时遇到的问题。当您的响应对象有太多字段时,问题就会变得很明显,这会引发错误:Method has Too muchparameters。示例 1 工作正常,但示例 2 失败。
示例 1 使用 HTTP.POST,其响应对象与示例 2 中使用的响应对象相同,示例 2 使用 HTTP.GET。
为什么 OpenFeign 会限制 HTTP.GET 方法中的字段,并抛出异常?我无法使用 HTTP.POST 来获取/获取/读取资源。BAD REST API 设计标准。
使用相同的响应对象,对于 HTTP.POST(有效),HTTP.GET 失败
public interface ClientFeignV2 {
//Example 1
@Headers("Content-Type: application/json") @RequestLine("POST api/v2/clients") ClientResponse findAllClientsByUid1(@RequestBody ClientRequest request);
//Example 2
@Headers("Content-Type: application/json")
@RequestLine("GET api/v2/clients/{uid}")
ClientResponse findAllClientsByUid(@PathVariable(value = "uid") String uid,
@RequestParam(value = "limit", required = false) Integer limit,
@RequestParam(value = "offset", required = false) Integer offset);
}
Run Code Online (Sandbox Code Playgroud)
堆栈跟踪:
Caused by: …Run Code Online (Sandbox Code Playgroud) 我有一个从 Visual studio 2019 (Ctrl+F5) 运行的 asp.net core 3.1 Web 服务器。它有一个 HTTP GET 端点,我可以在 VS Code 中使用 REST 客户端成功调用该端点:
GET https://localhost:5001/api/myResource
Run Code Online (Sandbox Code Playgroud)
然后我尝试开发一个从控制台运行的服务工作者(也是.net core 3.1),并且该调用是相同的资源。就像这样..
httpClient = new HttpClient();
var responseHTTP = await httpClient.GetAsync("https://localhost:5001/api/myResource");
Run Code Online (Sandbox Code Playgroud)
然后我得到的响应是来自我公司代理的错误消息(指出禁止访问 bla bla bla)以及实际发布的地址(响应内容的一部分):
尝试检索 URL 时:localhost.mycompany.com:5001
因此它添加了
mycompany.com
到我在中提供的地址httpClient.GetAsync()
我尝试在 Windows 设置中禁用代理(包括删除环境变量)并重新启动控制台和本地网络服务器。但它仍然通过代理(或者我从代理得到相同的禁止答案)。有没有办法绕过代理?我看过的所有问题和答案都是相反的,让 httpClient 使用代理。
我们正在审查系统的设计.并且需要验证我们认为可能是安全问题的内容.
在该系统中,一些敏感信息在查询字符串中发送.问题是:
我在ICS上遇到这个例外,而在2.2上运行正常.
java.lang.IllegalStateException: Target host must not be null, or set in parameters. scheme=null, host=null, path=http://maps.googleapis.com/maps/api/geocode/json?latlng=32.0692342,34.7952296&sensor=true
Run Code Online (Sandbox Code Playgroud)
这是我的代码:
HttpGet request = new HttpGet(URLEncoder.encode(requestUrl, "UTF-8"));
HttpResponse response;
response = mHttpClient.execute(request);
Run Code Online (Sandbox Code Playgroud) 我使用Jquery AJAX作为GET请求时遇到问题.由于某种原因,ASP.NET MVC模型绑定器似乎无法绑定到我的过滤器项.调用操作结果会发生什么,但会创建一个空对象.
但是,如果我从HTTP Get更改为HTTP Post,那么它可以工作.那为什么会这样?根据我的理解,最好使用GET,因为服务器上的数据没有变化.
这是我的代码的精简版:
AJAX:
$.ajax({
url: url,
contentType: 'application/json',
dataType: 'json',
type: "GET",
data: "{'filter':" + ko.toJSON(model.filter) + "}",
error: function (xhr, textStatus, errorThrown) {
},
success: function (returnedData) {
}
Run Code Online (Sandbox Code Playgroud)
的ActionResult:
[HttpGet]
public virtual ActionResult Index(IFilter filter)
{
ViewModel filteredViewModel = GetFilteredViewModel(filter);
if (Request.IsAjaxRequest())
{
return toJSON(filteredViewModel );
}
return View(filteredViewModel );
}
Run Code Online (Sandbox Code Playgroud)
过滤:
public class Filter: IFilter
{
public Nullable<DateTime> LogDate { get; set; }
public Nullable<int> SpecificItem_ID { get; set; }
}
Run Code Online (Sandbox Code Playgroud) 我在http连接中收到错误java.lang.IllegalArgumentException:索引76处的查询中出现非法字符.尝试了所有3个例子.无法解决它.Tried url_encode但它没有采取组件:局部性部分被考虑.我怎么做让这个网址工作.谢谢你.
BufferedReader in = null;
HttpClient httpclient = new DefaultHttpClient();
HttpGet request = new HttpGet();
URI website = new URI("http://maps.googleapis.com/maps/api/geocode/json?components=locality:Spokane|country=us|administrative_area:washington&address="+newText+"&sensor=false");
request.setURI(website);
HttpResponse response = httpclient.execute(request);
in = new BufferedReader(new InputStreamReader(
response.getEntity().getContent()));
String line = in.readLine();
data = line;
suggest = new ArrayList<String>();
Run Code Online (Sandbox Code Playgroud)
和
String uri =("http://maps.googleapis.com/maps/api/geocode/json?components=locality:Spokane|country=us|administrative_area:washington&address="+newText+"&sensor=false");
uri=URLEncoder.encode(uri,"UTF-8");
HttpClient hClient = new DefaultHttpClient();
HttpGet hGet = new HttpGet(uri);
ResponseHandler<String> rHandler = new BasicResponseHandler();
data = hClient.execute(hGet,rHandler);
suggest = new ArrayList<String>();
Run Code Online (Sandbox Code Playgroud)
和
String urlstr="http://maps.googleapis.com/maps/api/geocode/json?";
String str_parameters = "components=locality:Spokane|country=us|administrative_area:washington";
String encodedparams = …Run Code Online (Sandbox Code Playgroud)