Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/312.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/image/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 请举个例子_Java_Desire2learn - Fatal编程技术网

Java 请举个例子

Java 请举个例子,java,desire2learn,Java,Desire2learn,我正在尝试向valance发送一个用户更新,我正在寻找一个如何执行put的示例,特别是更新用户的put 我环顾四周,但没有看到如何使用UserContext使用Java发送json块的示例 任何指向文档的指针都将不胜感激。我可以分享一个使用api(与java相同的粗略逻辑)的项目中的php代码片段。用户上下文只准备url,特定环境(java运行时或php库)的框架用于发布和检索结果(在本例中使用的是php CURL) $apiPath=“/d2l/api/le/”。版本"/" . $库尔赛德。“

我正在尝试向valance发送一个用户更新,我正在寻找一个如何执行put的示例,特别是更新用户的put

我环顾四周,但没有看到如何使用UserContext使用Java发送json块的示例


任何指向文档的指针都将不胜感激。

我可以分享一个使用api(与java相同的粗略逻辑)的项目中的php代码片段。用户上下文只准备url,特定环境(java运行时或php库)的框架用于发布和检索结果(在本例中使用的是php CURL)

$apiPath=“/d2l/api/le/”。版本"/" . $库尔赛德。“/content/isbn/”;
$uri=$opContext->createAuthenticatedUri($apiPath,'POST');
$uri=str_replace(“https”,“http”,“$uri”);
curl_setopt($ch,CURLOPT_URL,$uri);
curl_setopt($ch,CURLOPT_POST,true);
$response=curl\u exec($ch);
$httpCode=curl\u getinfo($ch,CURLINFO\u HTTP\u代码);
$contentType=curl\u getinfo($ch,CURLINFO\u CONTENT\u TYPE);
$responseCode=$opContext->handleResult($response,$httpCode,$contentType);
$ret=json_decode($response,true);
如果($responseCode==D2LUserContext::RESULT\u ok)
{
$ret=“$response”;
$tryAgain=false;
}
elseif($responseCode==D2LUserContext::结果\u无效\u时间戳)
{
$tryAgain=true;
}
elseif(isset($ret['Errors'][0]['Message']))
{
if($ret['Errors'][0]['Message']==“无效ISBN”)
{
$allowedOrgId[]=$c;
}
$tryAgain=false;
}
post消息的跟踪示例如下:

PUT https://valence.desire2learn.com/d2l/api/lp/1.0/users/3691?x_b=TwULqrltMXvTE8utuLCN5O&x_a=L2Hd9WvDTcyiyu5n2AEgpg&x_d=OKuPjV-a0ZoSBuZvJkQLpFva2D59gNjTMiP8km6bdjk&x_c=UjCMpy1VNHsPCJOjKAE_92g1YqSxmebLHnQ0cbhoSPI&x_t=1336498251 HTTP/1.1
Accept-Encoding: gzip,deflate
Accept: application/json
Content-Type: application/json

{
"OrgDefinedId": "85033380",
"FirstName": "First",
"MiddleName": "Middle",
"LastName": "Last",
"ExternalEmail": "me@somehostname.com",
"UserName": "Username",
"Activation": {
        "IsActive": true
}
}

我可以分享一个使用api的项目中的php代码片段(与java的粗略逻辑相同)。用户上下文只准备url,特定环境(java运行时或php库)的框架用于发布和检索结果(在本例中使用的是php CURL)

$apiPath=“/d2l/api/le/”。版本"/" . $库尔赛德。“/content/isbn/”;
$uri=$opContext->createAuthenticatedUri($apiPath,'POST');
$uri=str_replace(“https”,“http”,“$uri”);
curl_setopt($ch,CURLOPT_URL,$uri);
curl_setopt($ch,CURLOPT_POST,true);
$response=curl\u exec($ch);
$httpCode=curl\u getinfo($ch,CURLINFO\u HTTP\u代码);
$contentType=curl\u getinfo($ch,CURLINFO\u CONTENT\u TYPE);
$responseCode=$opContext->handleResult($response,$httpCode,$contentType);
$ret=json_decode($response,true);
如果($responseCode==D2LUserContext::RESULT\u ok)
{
$ret=“$response”;
$tryAgain=false;
}
elseif($responseCode==D2LUserContext::结果\u无效\u时间戳)
{
$tryAgain=true;
}
elseif(isset($ret['Errors'][0]['Message']))
{
if($ret['Errors'][0]['Message']==“无效ISBN”)
{
$allowedOrgId[]=$c;
}
$tryAgain=false;
}
post消息的跟踪示例如下:

PUT https://valence.desire2learn.com/d2l/api/lp/1.0/users/3691?x_b=TwULqrltMXvTE8utuLCN5O&x_a=L2Hd9WvDTcyiyu5n2AEgpg&x_d=OKuPjV-a0ZoSBuZvJkQLpFva2D59gNjTMiP8km6bdjk&x_c=UjCMpy1VNHsPCJOjKAE_92g1YqSxmebLHnQ0cbhoSPI&x_t=1336498251 HTTP/1.1
Accept-Encoding: gzip,deflate
Accept: application/json
Content-Type: application/json

{
"OrgDefinedId": "85033380",
"FirstName": "First",
"MiddleName": "Middle",
"LastName": "Last",
"ExternalEmail": "me@somehostname.com",
"UserName": "Username",
"Activation": {
        "IsActive": true
}
}

在对这个问题进行修补之后,我的同事提出了很多建议(我不确定他是否愿意被确认,所以我就叫他比尔)。我们提出了以下Java方法(实际上应该分为不同的方法,但这是可以理解的)

私有静态字符串getValanceResult(ID2LUserContext-userContext),
URI、字符串查询、字符串sPost、字符串sMethod、int尝试){
String sError=“Error:发生未知错误”;
if(sMethod==null){
sMethod=“GET”;
}
URL连接;
试一试{
URL f=新URL(uri.toString()+查询);
//connection=uri.toURL().openConnection();
连接=f.openConnection();
}捕获(NullPointerException e){
返回“错误:必须验证”;
}捕获(格式错误){
return“Error:+e.getMessage();
}捕获(IOE异常){
return“Error:+e.getMessage();
}
StringBuilder sb=新的StringBuilder();
试一试{
//将连接强制转换为HttpURLConnection,以便我们可以检查
//状态码
HttpURLConnection httpConnection=(HttpURLConnection)连接;
httpConnection.setRequestMethod(sMethod);
httpConnection.setConnectTimeout(20000);
httpConnection.setReadTimeout(20000);
httpConnection.setUseCaches(false);
httpConnection.setDefaultUseCaches(false);
httpConnection.setDoOutput(true);
如果(!“”.equals(sPost)){
//设置连接
httpConnection.setDoInput(true);
setRequestProperty(“内容类型”、“应用程序/json”);
//执行连接并将xml发送到服务器
OutputStreamWriter writer=新的OutputStreamWriter(httpConnection.getOutputStream());
作家,作家(斯波斯特);
writer.flush();
writer.close();
}
缓冲读取器;
//如果状态代码为success,则从
//输入流
if(httpConnection.getResponseCode()==200){
in=新的BufferedReader(新的InputStreamReader(
httpConnection.getInputStream());
//否则,将从输出流读取主体
}否则{
in=新的BufferedReader(新的InputStreamReader(
httpConnection.getErrorStream());
}
字符串输入线;
而((inputLine=in.readLine())!=null){
某人附加(输入线);
}
in.close();
//确定rest调用的结果并自动调整
//时间戳无效时的用户上下文
int r