Java使用示例
import java.util.UUID;
import com.aliyuncs.CommonRequest;
import com.aliyuncs.CommonResponse;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.http.FormatType;
import com.aliyuncs.http.MethodType;
import com.aliyuncs.profile.DefaultProfile;
import com.aliyuncs.profile.IClientProfile;
public class NlpSdkTestSmaple {
public static void main(String[] args) {
String accessKeyId = "yourAccessKeyId";
String accessKeySecret = "yourAccessKeySecret";
try {
DefaultProfile.addEndpoint("cn-shanghai", "cn-shanghai", "Nlp", "nlp.cn-shanghai.aliyuncs.com");
IClientProfile profile = DefaultProfile.getProfile("cn-shanghai", accessKeyId, accessKeySecret);
IAcsClient client = new DefaultAcsClient(profile);
String postBody = "{\n"
+ " \"text\": \"Iphone专用数据线\",\n"
+ " \"lang\": \"ZH\"\n" + "}";
CommonRequest request = new CommonRequest();
request.setDomain("nlp.cn-shanghai.aliyuncs.com"); // 必须设置domain
request.setUriPattern("/nlp/api/wordsegment/general"); // 设置所要请求的API路径
request.setMethod(MethodType.POST); // 设置请求方式,目前只支持POST
request.setHttpContent(postBody.getBytes(), "utf-8", FormatType.JSON); // 设置请求内容以及格式
request.putHeadParameter("x-acs-signature-method", "HMAC-SHA1");
request.putHeadParameter("x-acs-signature-nonce", UUID.randomUUID().toString()); // 设置请求唯一码,防止网络重放攻击
request.setVersion("2018-04-08");
CommonResponse response = client.getCommonResponse(request); // 请求并获取结果
System.out.println(response.getData());
} catch (ClientException e) {
e.printStackTrace();
}
}
}
在文档使用中是否遇到以下问题
更多建议
匿名提交