如何使用php发送此GCM下游消息(HTTP POST REQUEST)?

时间:2015-12-12 23:55:30

标签: php android ajax google-cloud-messaging http-post

我对php语法相当新,我了解如何接收http post请求,以及php中的GET请求,但我不知道如何在没有表单的情况下在php中正确发送http post请求,使用数据如下。 (我知道我可以使用ajax,但我想学习如何使用php脚本)。

<!doctype html>
<html ng-app="stalkcalibrator">
<head>
  <title>Corn Stalk Calibrator</title>
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" />
  <link rel="stylesheet" href="style/style.css"/>
  <script src="angular.js"></script>
  <script src="controllers.js"></script>
</head>

<body ng-controller="adminController">

  <h1 id="title">Calibrator - Admin Upload</h1>
  <!-- back to admin home -->
  <div id="back"><a href="admin.html">Admin Home</a></div>

  <!-- form used to upload one or more images -->
  <form>
    <!-- button allows user to browse local directory for image -->
    <!-- ng-model saves image var in array -->
    Upload image <input type="file" ng-model="img" accept="image/*" id="file" />

    <!-- executes js upload function with uploaded images -->
    <button><a ng-click="upload()">Submit</a></button>

    <p ng-model="num">{{num}}</p>

  </form>

</body>

</html>
var stalkcalibrator = angular.module('stalkcalibrator', []);

stalkcalibrator.controller('adminController', function($scope){

  //array of data for each stalk. PULL FROM JSON FILE!
  $scope.stalks = [{id:1, name:2, thumbnail:3, note:4}, {id:9, name:10, thumbnail:11, note:12}, {id:5, name:6, thumbnail:7, note:8}];

  //array of image uploads
  $scope.img;

$scope.num = 1;

  function getStalks($scope){

  }

  $scope.upload = function() {
    $http({
        headers: {'Authorization': 'Client-ID 010fe699c18e3c9'},
        url: 'https://api.imgur.com/3/',
        type: 'POST',
        data: {'image': $scope.img}
    }).then(function successCallback(response) {
    // this callback will be called asynchronously
    // when the response is available
    $scope.num = 2;
  }, function errorCallback(response) {
    // called asynchronously if an error occurs
    // or server returns response with an error status.
    $scope.num = 3;
  });


    //adds image data to JSON file
    //_TODO_

  };

});

1 个答案:

答案 0 :(得分:0)

此代码适用于Android。

尝试按照底部作为示例。您可以将此代码粘贴到http://phpfiddle.org/中。尝试通过添加要发送的消息(即分数和时间)来了解逻辑流如何工作并弄乱代码。我在实施推送通知时发现了这段代码。为了使下面的代码工作,您将需要授权密钥以及设备注册令牌。祝你好运!

Exception in thread "main" java.lang.NoSuchMethodError: org.apache.jena.atlas.lib.Cache.getIfPresent(Ljava/lang/Object;)Ljava/lang/Object;
  at org.apache.jena.enhanced.EnhGraph.getNodeAs(EnhGraph.java:133)
  at org.apache.jena.rdf.model.impl.IteratorFactory.asResource(IteratorFactory.java:71)
  at org.apache.jena.rdf.model.impl.IteratorFactory.asResource(IteratorFactory.java:62)
  at org.apache.jena.rdf.model.impl.ModelCom.getResource(ModelCom.java:888)
  at org.apache.jena.rdf.model.impl.ModelCom.createResource(ModelCom.java:1338)
  at com.lymba.proposal.summarizer.core.rdf.TestRdf.testRdf(TestRdf.java:15)
  at com.lymba.proposal.summarizer.core.rdf.TestRdf.main(TestRdf.java:21)