我已经编写了Google云功能(HTTP触发器)。它在google云界面中成功测试。现在,我需要从Unity Game(C#.Net核心)中调用它。
首先,我尝试从浏览器运行它。我带了显示在Google云功能界面中的URL。这是行不通的。我没有得到stackdriver日志(它甚至没有命中URL?)。 是因为它需要oauth 2.0令牌吗?
我正在创建Http请求,嵌入JSON
request.ContentType = "application/json";
request.Method = "POST";
request.Headers["Authorization"] = "Bearer " + token;
//token obtained from oauth 2.0 JWT call
byte[] JsonContentBytes = Encoding.UTF8.GetBytes(strjsonReqContent);
// my Json object. requestJSON.ToString());
request.ContentLength = JsonContentBytes.Length;
在这里,我也尝试使用Oauth 2.0令牌。 (它适用于存储API。我的云功能服务帐户具有项目编辑者访问权限)
我从云项目外部看到了一篇有关使用云功能的文章。它没有解决我的问题。
请让我知道从云项目外部使用云功能的所有条件。
EDIT1:
谢谢你的建议。这是Curl执行的日志。我不习惯进行网络调试。请提出我应该进一步检查的内容。我可以确定这是“错误请求”。该URL是我从云功能控制台中选择的URL。
>curl -v -X POST https://us-central1- myproject.cloudfunctions.net/myfunctiontest -H "Content-Type:application/json" -d '{"username":"myemail@mydomain.com","password":"password1"}'
Note: Unnecessary use of -X or --request, POST is already inferred.
* Trying 172.217.163.174...
* TCP_NODELAY set
* Connected to us-central1-myproject.cloudfunctions.net (172.217.163.174) port 443 (#0)
* schannel: SSL/TLS connection with us-central1-myproject.cloudfunctions.net port 443 (step 1/3)
* schannel: checking server certificate revocation
* schannel: sending initial handshake data: sending 212 bytes...
* schannel: sent initial handshake data: sent 212 bytes
* schannel: SSL/TLS connection with us-central1-myproject.cloudfunctions.net port 443 (step 2/3)
* schannel: failed to receive handshake, need more data
* schannel: SSL/TLS connection with us-central1-myproject.cloudfunctions.net port 443 (step 2/3)
* schannel: encrypted data got 4096
* schannel: encrypted data buffer: offset 4096 length 4096
* schannel: encrypted data length: 4028
* schannel: encrypted data buffer: offset 4028 length 4096
* schannel: received incomplete message, need more data
* schannel: SSL/TLS connection with us-central1-myproject.cloudfunctions.net port 443 (step 2/3)
* schannel: encrypted data got 1024
* schannel: encrypted data buffer: offset 5052 length 5052
* schannel: received incomplete message, need more data
* schannel: SSL/TLS connection with us-central1-myproject.cloudfunctions.net port 443 (step 2/3)
* schannel: encrypted data got 1024
* schannel: encrypted data buffer: offset 6076 length 6076
* schannel: received incomplete message, need more data
* schannel: SSL/TLS connection with us-central1-myproject.cloudfunctions.net port 443 (step 2/3)
* schannel: encrypted data got 1024
* schannel: encrypted data buffer: offset 7100 length 7100
* schannel: received incomplete message, need more data
* schannel: SSL/TLS connection with us-central1-myproject.cloudfunctions.net port 443 (step 2/3)
* schannel: encrypted data got 1024
* schannel: encrypted data buffer: offset 8124 length 8124
* schannel: received incomplete message, need more data
* schannel: SSL/TLS connection with us-central1-myproject.cloudfunctions.net port 443 (step 2/3)
* schannel: encrypted data got 317
* schannel: encrypted data buffer: offset 8441 length 9148
* schannel: sending next handshake data: sending 93 bytes...
* schannel: SSL/TLS connection with us-central1-myproject.cloudfunctions.net port 443 (step 2/3)
* schannel: encrypted data got 284
* schannel: encrypted data buffer: offset 284 length 9148
* schannel: SSL/TLS handshake complete
* schannel: SSL/TLS connection with us-central1-myproject.cloudfunctions.net port 443 (step 3/3)
* schannel: stored credential handle in session cache
> POST /logontest HTTP/1.1
> Host: us-central1-myproject.cloudfunctions.net
> User-Agent: curl/7.55.1
> Accept: */*
> Content-Type:application/json
> Content-Length: 59
>
* upload completely sent off: 59 out of 59 bytes
* schannel: client wants to read 102400 bytes
* schannel: encdata_buffer resized 103424
* schannel: encrypted data buffer: offset 0 length 103424
* schannel: encrypted data got 506
* schannel: encrypted data buffer: offset 506 length 103424
* schannel: decrypted data length: 477
* schannel: decrypted data added: 477
* schannel: decrypted data cached: offset 477 length 102400
* schannel: encrypted data buffer: offset 0 length 103424
* schannel: decrypted data buffer: offset 477 length 102400
* schannel: schannel_recv cleanup
* schannel: decrypted data returned 477
* schannel: decrypted data buffer: offset 0 length 102400
< HTTP/1.1 400 Bad Request
< Content-Type: text/html
< Function-Execution-Id: qyx8g4vv8hn1
< X-Cloud-Trace-Context: 6f8012ea791b4a0f900ac4b84debaf5f;o=1
< Date: Thu, 02 May 2019 13:23:14 GMT
< Server: Google Frontend
< Content-Length: 192
< Alt-Svc: quic=":443"; ma=2592000; v="46,44,43,39"
<
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<title>400 Bad Request</title>
<h1>Bad Request</h1>
<p>The browser (or proxy) sent a request that this server could not
understand.</p>
* Connection #0 to host us-central1-myproject.cloudfunctions.net left intact
“错误请求”可能不是由于URL引起的,因为我来自云功能UI。请提出我应该如何进行。谢谢。