Ibm mobilefirst 无法调用MobileFirst 8.0 PushNotification Rest端点 我试图通过MobiLe1.1基金会8服务器获得向移动应用程序发送推送通知的授权令牌。我已经编写了以下代码来发送请求,但我不确定我把事情搞砸了,因为我得到的响应不包含令牌: import java.io.IOException; import java.util.ArrayList; import java.util.List; import org.apache.http.HttpHost; import org.apache.http.HttpResponse; import org.apache.http.client.ClientProtocolException; import org.apache.http.client.HttpClient; import org.apache.http.client.entity.UrlEncodedFormEntity; import org.apache.http.client.methods.HttpPost; import org.apache.http.impl.client.DefaultHttpClient; import org.apache.http.message.BasicNameValuePair; import org.apache.http.protocol.HTTP; import org.apache.wink.client.ClientConfig; import org.apache.wink.client.ClientResponse; import org.apache.wink.client.Resource; import org.apache.wink.client.RestClient; public class SendPushNotification { private String MFP_SERVER_URL = "1.2.3.4"; private int MFP_SERVER_PORT = 1234; private static String URI_GET_TOKEN = "mfp/api/az/v1/token"; private static String URI_SEND_MESSAGE = "imfpush/v1/apps/my.app/messages"; private HttpClient client = new DefaultHttpClient(); private HttpHost host = new HttpHost(MFP_SERVER_URL,MFP_SERVER_PORT,"http");; private HttpPost post; public HttpResponse invokeRestfulService(String uri) throws ClientProtocolException, IOException{ List<BasicNameValuePair> parametersBody = new ArrayList<BasicNameValuePair>(); parametersBody.add(new BasicNameValuePair("grant_type","client_credentials")); parametersBody.add(new BasicNameValuePair("scope","access.sendMessage push.application.my.app messages.write")); post = new HttpPost(uri); post.setHeader("Authorization", "Basic Z292Lm1zLmFjY2Vzcy5wdXNoY2xpZW50OjJmaWxldWkudWF0"); post.setHeader("Content-type", "application/x-www-form-urlencoded"); post.setEntity(new UrlEncodedFormEntity(parametersBody, HTTP.UTF_8)); return client.execute(host,post); } public static void main(String[] args) throws ClientProtocolException, IOException{ SendPushNotification notification = new SendPushNotification(); HttpResponse httpResponse = notification.invokeRestfulService(URI_GET_TOKEN); System.out.println(httpResponse); notification.restClient(); } public void restClient(){ ClientConfig config = new ClientConfig(); config.setBypassHostnameVerification(true); RestClient restClient = new RestClient(config); Resource unprotectedResource = restClient.resource( "http://"+MFP_SERVER_URL + ":" + MFP_SERVER_PORT); unprotectedResource.header( "Content-Type", "application/x-www-form-urlencoded"); unprotectedResource.header( "Authorization", "Basic Z292Lm1zLmFjY2Vzcy5wdXNoY2xpZW50OjJmaWxldWkudWF0"); unprotectedResource.attribute("grant_type", "client_credentials"); unprotectedResource.attribute("scope", "access.sendMessage push.application.gov.ms.tofileui messages.write"); ClientResponse clientResponse = unprotectedResource.contentType("application/x-www-form-urlencoded").accept("*/*").post(URI_GET_TOKEN); System.out.println(clientResponse.getEntity(String.class)); } } import java.io.IOException; 导入java.util.ArrayList; 导入java.util.List; 导入org.apache.http.HttpHost; 导入org.apache.http.HttpResponse; 导入org.apache.http.client.ClientProtocolException; 导入org.apache.http.client.HttpClient; 导入org.apache.http.client.entity.UrlEncodedFormEntity; 导入org.apache.http.client.methods.HttpPost; 导入org.apache.http.impl.client.DefaultHttpClient; 导入org.apache.http.message.BasicNameValuePair; 导入org.apache.http.protocol.http; 导入org.apache.wink.client.ClientConfig; 导入org.apache.wink.client.ClientResponse; 导入org.apache.wink.client.Resource; 导入org.apache.wink.client.RestClient; 公共类发送通知{ 专用字符串MFP_SERVER_URL=“1.2.3.4”; 专用int MFP_服务器_端口=1234; 私有静态字符串URI_GET_TOKEN=“mfp/api/az/v1/TOKEN”; 私有静态字符串URI\u SEND\u MESSAGE=“imfpush/v1/apps/my.app/messages”; 私有HttpClient=new DefaultHttpClient(); 私有HttpHost主机=新HttpHost(MFP_服务器_URL,MFP_服务器_端口,“http”);; 私人HttpPost; 公共HttpResponse invokeRestfulService(字符串uri)抛出ClientProtocolException,IOException{ 列表参数body=new ArrayList(); 参数body.add(新的BasicNameValuePair(“授权类型”、“客户端凭据”); 参数body.add(新的BasicNameValuePair(“作用域”、“access.sendMessage push.application.my.app messages.write”); post=新的HttpPost(uri); post.setHeader(“授权”、“基本Z292LM1ZLMFJY2VZCY5WDXNOY2XPZW50OJMAWXLDWKUDF0”); post.setHeader(“内容类型”、“应用程序/x-www-form-urlencoded”); setEntity(新的UrlEncodedFormEntity(参数body,HTTP.UTF_8)); 返回client.execute(主机、post); } 公共静态void main(字符串[]args)抛出ClientProtocolException,IOException{ SendPushNotification通知=新建SendPushNotification(); HttpResponse HttpResponse=notification.invokeRestfulService(URI\u GET\u令牌); System.out.println(httpResponse); restClient(); } public-void-restClient(){ ClientConfig=newclientconfig(); config.setBypassHostnameVerification(true); RestClient RestClient=新的RestClient(配置); Resource unprotectedResource=restClient.Resource(“http://“+MFP_服务器_URL+”:“+MFP_服务器_端口”); unprotectedResource.header(“内容类型”、“应用程序/x-www-form-urlencoded”); 未受保护的资源标头(“授权”、“基本Z292LM1ZLMFJY2VZCY5WDXNOY2XPZW50OJMAWXLDWKUDF0”); 未受保护的资源属性(“授权类型”、“客户端凭据”); unprotectedResource.attribute(“scope”、“access.sendMessage push.application.gov.ms.tofileui messages.write”); ClientResponse ClientResponse=unprotectedResource.contentType(“application/x-www-form-urlencoded”).accept(“*/*”).post(URI\u GET\u令牌); System.out.println(clientResponse.getEntity(String.class)); } }

Ibm mobilefirst 无法调用MobileFirst 8.0 PushNotification Rest端点 我试图通过MobiLe1.1基金会8服务器获得向移动应用程序发送推送通知的授权令牌。我已经编写了以下代码来发送请求,但我不确定我把事情搞砸了,因为我得到的响应不包含令牌: import java.io.IOException; import java.util.ArrayList; import java.util.List; import org.apache.http.HttpHost; import org.apache.http.HttpResponse; import org.apache.http.client.ClientProtocolException; import org.apache.http.client.HttpClient; import org.apache.http.client.entity.UrlEncodedFormEntity; import org.apache.http.client.methods.HttpPost; import org.apache.http.impl.client.DefaultHttpClient; import org.apache.http.message.BasicNameValuePair; import org.apache.http.protocol.HTTP; import org.apache.wink.client.ClientConfig; import org.apache.wink.client.ClientResponse; import org.apache.wink.client.Resource; import org.apache.wink.client.RestClient; public class SendPushNotification { private String MFP_SERVER_URL = "1.2.3.4"; private int MFP_SERVER_PORT = 1234; private static String URI_GET_TOKEN = "mfp/api/az/v1/token"; private static String URI_SEND_MESSAGE = "imfpush/v1/apps/my.app/messages"; private HttpClient client = new DefaultHttpClient(); private HttpHost host = new HttpHost(MFP_SERVER_URL,MFP_SERVER_PORT,"http");; private HttpPost post; public HttpResponse invokeRestfulService(String uri) throws ClientProtocolException, IOException{ List<BasicNameValuePair> parametersBody = new ArrayList<BasicNameValuePair>(); parametersBody.add(new BasicNameValuePair("grant_type","client_credentials")); parametersBody.add(new BasicNameValuePair("scope","access.sendMessage push.application.my.app messages.write")); post = new HttpPost(uri); post.setHeader("Authorization", "Basic Z292Lm1zLmFjY2Vzcy5wdXNoY2xpZW50OjJmaWxldWkudWF0"); post.setHeader("Content-type", "application/x-www-form-urlencoded"); post.setEntity(new UrlEncodedFormEntity(parametersBody, HTTP.UTF_8)); return client.execute(host,post); } public static void main(String[] args) throws ClientProtocolException, IOException{ SendPushNotification notification = new SendPushNotification(); HttpResponse httpResponse = notification.invokeRestfulService(URI_GET_TOKEN); System.out.println(httpResponse); notification.restClient(); } public void restClient(){ ClientConfig config = new ClientConfig(); config.setBypassHostnameVerification(true); RestClient restClient = new RestClient(config); Resource unprotectedResource = restClient.resource( "http://"+MFP_SERVER_URL + ":" + MFP_SERVER_PORT); unprotectedResource.header( "Content-Type", "application/x-www-form-urlencoded"); unprotectedResource.header( "Authorization", "Basic Z292Lm1zLmFjY2Vzcy5wdXNoY2xpZW50OjJmaWxldWkudWF0"); unprotectedResource.attribute("grant_type", "client_credentials"); unprotectedResource.attribute("scope", "access.sendMessage push.application.gov.ms.tofileui messages.write"); ClientResponse clientResponse = unprotectedResource.contentType("application/x-www-form-urlencoded").accept("*/*").post(URI_GET_TOKEN); System.out.println(clientResponse.getEntity(String.class)); } } import java.io.IOException; 导入java.util.ArrayList; 导入java.util.List; 导入org.apache.http.HttpHost; 导入org.apache.http.HttpResponse; 导入org.apache.http.client.ClientProtocolException; 导入org.apache.http.client.HttpClient; 导入org.apache.http.client.entity.UrlEncodedFormEntity; 导入org.apache.http.client.methods.HttpPost; 导入org.apache.http.impl.client.DefaultHttpClient; 导入org.apache.http.message.BasicNameValuePair; 导入org.apache.http.protocol.http; 导入org.apache.wink.client.ClientConfig; 导入org.apache.wink.client.ClientResponse; 导入org.apache.wink.client.Resource; 导入org.apache.wink.client.RestClient; 公共类发送通知{ 专用字符串MFP_SERVER_URL=“1.2.3.4”; 专用int MFP_服务器_端口=1234; 私有静态字符串URI_GET_TOKEN=“mfp/api/az/v1/TOKEN”; 私有静态字符串URI\u SEND\u MESSAGE=“imfpush/v1/apps/my.app/messages”; 私有HttpClient=new DefaultHttpClient(); 私有HttpHost主机=新HttpHost(MFP_服务器_URL,MFP_服务器_端口,“http”);; 私人HttpPost; 公共HttpResponse invokeRestfulService(字符串uri)抛出ClientProtocolException,IOException{ 列表参数body=new ArrayList(); 参数body.add(新的BasicNameValuePair(“授权类型”、“客户端凭据”); 参数body.add(新的BasicNameValuePair(“作用域”、“access.sendMessage push.application.my.app messages.write”); post=新的HttpPost(uri); post.setHeader(“授权”、“基本Z292LM1ZLMFJY2VZCY5WDXNOY2XPZW50OJMAWXLDWKUDF0”); post.setHeader(“内容类型”、“应用程序/x-www-form-urlencoded”); setEntity(新的UrlEncodedFormEntity(参数body,HTTP.UTF_8)); 返回client.execute(主机、post); } 公共静态void main(字符串[]args)抛出ClientProtocolException,IOException{ SendPushNotification通知=新建SendPushNotification(); HttpResponse HttpResponse=notification.invokeRestfulService(URI\u GET\u令牌); System.out.println(httpResponse); restClient(); } public-void-restClient(){ ClientConfig=newclientconfig(); config.setBypassHostnameVerification(true); RestClient RestClient=新的RestClient(配置); Resource unprotectedResource=restClient.Resource(“http://“+MFP_服务器_URL+”:“+MFP_服务器_端口”); unprotectedResource.header(“内容类型”、“应用程序/x-www-form-urlencoded”); 未受保护的资源标头(“授权”、“基本Z292LM1ZLMFJY2VZCY5WDXNOY2XPZW50OJMAWXLDWKUDF0”); 未受保护的资源属性(“授权类型”、“客户端凭据”); unprotectedResource.attribute(“scope”、“access.sendMessage push.application.gov.ms.tofileui messages.write”); ClientResponse ClientResponse=unprotectedResource.contentType(“application/x-www-form-urlencoded”).accept(“*/*”).post(URI\u GET\u令牌); System.out.println(clientResponse.getEntity(String.class)); } },ibm-mobilefirst,mobilefirst-server,Ibm Mobilefirst,Mobilefirst Server,我尝试了两种不同的发送请求的方法,但得到的响应是400个错误的请求。尝试将字符串URI_GET_TOKEN=“mfp/api/az/v1/TOKEN”更改为字符串URI_GET_TOKEN=“/mfp/api/az/v1/TOKEN”Hi Prerak。就像你最近的另一篇/相关文章一样,这里的追踪会非常有用。请附上它,这将帮助我们确定问题可能是什么。谢谢

我尝试了两种不同的发送请求的方法,但得到的响应是400个错误的请求。

尝试将字符串URI_GET_TOKEN=“mfp/api/az/v1/TOKEN”更改为字符串URI_GET_TOKEN=“/mfp/api/az/v1/TOKEN”

Hi Prerak。就像你最近的另一篇/相关文章一样,这里的追踪会非常有用。请附上它,这将帮助我们确定问题可能是什么。谢谢