Google Cloud Storage 500内部服务器错误

时间:2018-12-08 11:57:07

标签: php google-cloud-platform google-cloud-storage

SettingsController.php :         

import java.io.File;
import java.io.FileInputStream;

import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.InputStreamEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
import org.junit.Assert;
import org.testng.annotations.Test;

import io.restassured.path.json.JsonPath;
import io.restassured.path.xml.XmlPath;
@Test
            public void getMethod() throws Exception  {
                //wsdl file :http://currencyconverter.kowabunga.net/converter.asmx?wsdl
                File soapRequestFile = new File(".\\SOAPRequest\\SoapRequestFile.xml");

                CloseableHttpClient client = HttpClients.createDefault(); //create client
                HttpPost request = new HttpPost("http://currencyconverter.kowabunga.net/converter.asmx"); //Create the request
                request.addHeader("Content-Type", "text/xml"); //adding header
                request.setEntity(new InputStreamEntity(new FileInputStream(soapRequestFile)));
                CloseableHttpResponse response =  client.execute(request);//Execute the command

                int statusCode=response.getStatusLine().getStatusCode();//Get the status code and assert
                System.out.println("Status code: " +statusCode );
                Assert.assertEquals(200, statusCode);

                String responseString = EntityUtils.toString(response.getEntity(),"UTF-8");//Getting the Response body
                System.out.println(responseString);


                XmlPath jsXpath= new XmlPath(responseString);//Converting string into xml path to assert
                String rate=jsXpath.getString("GetConversionRateResult");
                System.out.println("rate returned is: " +  rate);



        }

因此,我根据文档编写了这段代码,但是我总是遇到500 Network Error。

这是我的 index.php

    namespace App\Controllers;

    use Google\Cloud\Storage\StorageClient;

    class SettingsController extends Controller {

        public function createBucket($request, $response) {
            $projectId = 'myProjectId'; //here I specified my projectId 

            $storage = new StorageClient([
                'projectId' => $projectId
            ]);

            $bucketName = 'socnetfilestestkekdsfa213kfh34';
            $bucket = $storage->createBucket($bucketName);
        }
     }

这是我的项目结构:

backend project structure

1 个答案:

答案 0 :(得分:0)

最后,我已经解决了问题。 正如我提到的,require __DIR__ . '/../vendor/autoload.php';是正确的。就我而言,500错误的原因是环境变量。对于已部署的应用程序,您应该将服务Google云帐户密钥config.json放入项目中。我把我的放在一个配置文件夹中(检查上面的项目结构)。 这意味着在Heroku的“设置”中,我需要指定 GOOGLE_APPLICATION_CREDENTIALS: ../ config / yourAppName.json

感谢这篇文章: https://medium.com/@naz_islam/how-to-authenticate-google-cloud-services-on-heroku-for-node-js-app-dda9f4eda798