我试图用这个代码从手持设备(Windows CE/Compact框架)调用REST方法:
public static HttpWebRequest SendHTTPRequestNoCredentials(string uri, HttpMethods method, string data, string contentType)
{
ExceptionLoggingService.Instance.WriteLog("Reached
fileXferREST.SendHTTPRequestNoCredentials");
WebRequest request = null;
try
{
request = WebRequest.Create(uri);
request.Method = Enum.ToObject(typeof(HttpMethods), method).ToString();
request.ContentType = contentType;
((HttpWebRequest)request).Accept = contentType;
((HttpWebRequest)request).KeepAlive = false;
((HttpWebRequest)request).ProtocolVersion = HttpVersion.Version10;
if (method != HttpMethods.GET && method != HttpMethods.DELETE)
{
byte[] arrData = Encoding.UTF8.GetBytes(data);
request.ContentLength = arrData.Length;
using (Stream oS = request.GetRequestStream())
{
oS.Write(arrData, 0, arrData.Length);
}
}
else
{
request.ContentLength = 0;
}
}
catch (Exception ex)
{
String …Run Code Online (Sandbox Code Playgroud) ssl compact-framework remote-host socketexception get-request
我正在测试下面的代码以发送带有参数的 GET 请求,当参数的值是包含空格的字符串时,此代码会失败,例如:http://company.com/example.php?value=Jhon 123。如果我发送Jhon123(没有任何空格)就可以正常工作了。
为什么会出现这种情况?
private static void sendGet(String site, String params) throws Exception {
site += params;
URL obj = new URL(site);
try {
HttpURLConnection con = (HttpURLConnection) obj.openConnection();
// optional default is GET
con.setRequestMethod("GET");
int responseCode = con.getResponseCode();
System.out.println("\nSending 'GET' request to URL : " + site);
System.out.println("Response Code : " + responseCode);
BufferedReader in = new BufferedReader(
new InputStreamReader(con.getInputStream()));
String inputLine;
StringBuffer response = new StringBuffer();
while ((inputLine = in.readLine()) != null) { …Run Code Online (Sandbox Code Playgroud) 我尝试了所有方法,但它不起作用,我知道有一些类似的问题有答案,但这些问题是 5 年前提出的,不是最新的,也不起作用。
我的问题是:如何使用 Domino 数据服务 Rest-Api 搜索字段值。
我使用的网址:GET http(s)://{database}/api/data/documents?search=[fieldname]%20CONTAINS%20VALUE
这个网址不起作用。我总是得到一个错误。
错误:
"code":400,
"text":"Bad Request",
"message":"Database is not full text indexed.",
"type":"text",
"data":"com.ibm.domino.services.ServiceException: Database is not full text indexed.\r\n\tat...
Run Code Online (Sandbox Code Playgroud)
提前致谢!
我编写了一个程序,它将tcp请求发送到命令行中指定的Web地址并打印响应.当我将此请求发送到www.google.co.uk(或任何网站)时,我得不到任何回复:(
有人可以告诉我我做错了什么,以及谷歌的正确GET请求应该是什么样子.这是代码......
#include <WinSock2.h>
#include <WS2tcpip.h>
#include <stdio.h>
#pragma comment(lib, "Ws2_32.lib")
int main(int argc, char *argv[]){
WSADATA wsaData;
int iResult;
//Initialize Winsock
iResult = WSAStartup(MAKEWORD(2,2), &wsaData);
if(iResult != 0){
printf("WSAStartup failed: %d\n", iResult);
return 1;
}
struct addrinfo *result = NULL,
*ptr = NULL,
hints;
ZeroMemory(&hints, sizeof(hints));
hints.ai_family = AF_INET;
hints.ai_socktype = SOCK_STREAM;
hints.ai_protocol = IPPROTO_TCP;
#define DEFAULT_PORT "80"
//Resolve the server address and port
iResult = getaddrinfo(argv[1], DEFAULT_PORT, &hints, &result);
if(iResult != 0){
printf("getaddrinfo failed: %d\n", iResult);
WSACleanup();
return …Run Code Online (Sandbox Code Playgroud) 我正在构建一项调查,当用户回答问题时,我将答案附加到带有参数的 url 字符串中,并向我的服务器发送 get 请求。因此,对于每个答案,都会记录所选答案、时间戳和调查的唯一 ID。
我不确定最好的方法,但这就是我到目前为止所拥有的。
我创建了 url 和查询项。
var urlComponents: URLComponents {
let resultID = surveyQuestions.resultId
print("\(String(describing: resultID))")
let resultResponseID = surveyQuestions.questions[surveyResultResponseId]
print("\(String(describing: resultResponseID))")
let questionIndex = questionNumbers
print("\(String(describing: questionIndex))")
var urlComponents = URLComponents(string: "My String URL")
urlComponents?.queryItems = [
URLQueryItem(name: "surveyResultsId", value: "\(String(describing: resultID))"),
URLQueryItem(name: "surveyResultsResponseId", value: "\(String(describing: resultResponseID))"),
URLQueryItem(name: "questions", value: "\(questionIndex)"),
URLQueryItem(name: "selectedAnswer", value: "\(storedAnswer)")
]
let url = urlComponents?.url
print(url!.absoluteString as Any)
return urlComponents!
}
Run Code Online (Sandbox Code Playgroud)
然后我构建发送请求。
func sendRequest(_ url: String, parameters: [String: String], completion: …Run Code Online (Sandbox Code Playgroud) 我的http:// localhost:8888 / VGL / public / category / 18?sty = 3
当dd($request->sty);等于3
但是我把$request->sty在whereHas为
未定义的变量:请求
public function show(Request $request, $id)
{
$products = Product::with('features')
->whereHas('features', function ($q) {
return $q->where('id', $request->sty);
})
->where('category_id',17)
->get();
}
Run Code Online (Sandbox Code Playgroud) 我试图从 url 中获取一个或多或少如下所示的值:
http://localhost:8000/new-user/7
Run Code Online (Sandbox Code Playgroud)
在 url 中作为参数传递的这个数字 7 是我从刀片表单提交的 ID,作为对我在控制器中执行的操作的请求,但无论如何我都无法获得此值。这是我到目前为止尝试过的:
我试图在我提交表单的控制器中使用它
$request->route('company_id');
Run Code Online (Sandbox Code Playgroud)
我还尝试将其作为正确的 GET 参数:
<input type="hidden" name="company_id" id="company_id" value="{{app('request')->input('company_id')}}">
Run Code Online (Sandbox Code Playgroud)
我也试过这个:
<input type="hidden" name="company_id" id="company_id" value="{{Input::get('company_id')}}">
Run Code Online (Sandbox Code Playgroud)
和这个:
<input type="hidden" name="company_id" id="company_id" value="{{$_GET['company_id']}}">
Run Code Online (Sandbox Code Playgroud)
没有 os 这些选项工作,我仍然收到一个空值。
关于如何获得此变量的任何想法或建议?
谢谢!
get-request ×7
http ×2
laravel ×2
c++ ×1
httprequest ×1
ibm-domino ×1
java ×1
lotus-domino ×1
lotus-notes ×1
php ×1
remote-host ×1
ssl ×1
swift ×1
swift4 ×1
tcp ×1
winsock ×1