Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/401.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 Microsoft扬声器识别API:Ressource或Path can';找不到_Java_Web Services - Fatal编程技术网

Java Microsoft扬声器识别API:Ressource或Path can';找不到

Java Microsoft扬声器识别API:Ressource或Path can';找不到,java,web-services,Java,Web Services,您好,我正在尝试Microsoft speaker identification API并使用注册服务。但我在回答中发现了这个错误 {“error”:{“code”:“NotFound”,“message”:“无法找到资源或路径”。} 这是我的班级代码: 包com.msconginitive.speakeridentification import java.io.File; import java.net.URI; import org.apache.http.HttpEntity; impo

您好,我正在尝试Microsoft speaker identification API并使用注册服务。但我在回答中发现了这个错误

{“error”:{“code”:“NotFound”,“message”:“无法找到资源或路径”。}

这是我的班级代码: 包com.msconginitive.speakeridentification

import java.io.File;
import java.net.URI;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.utils.URIBuilder;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.FileEntity;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;

public class JavaSample 
{
    public static void main(String[] args) 
    {
        HttpClient httpclient = HttpClients.createDefault();

        try
        {
            URIBuilder builder = new URIBuilder("https://westus.api.cognitive.microsoft.com/spid/v1.0/identificationProfiles/1/enroll");
            builder.setParameter("shortAudio", "true");
            URI uri = builder.build();
            System.out.println(uri);
            HttpPost request = new HttpPost(uri);
            request.setHeader("Content-Type", "multipart/form-data");
            request.setHeader("Ocp-Apim-Subscription-Key", "b91fbd3dc22842d68e4ee1c81578d6be");
            //System.out.println(request.);


            // Request body
            File file = new File("C:\\Users\\dsghaier\\Desktop\\Records\\dhia1.wav");
            System.out.println(file.length());
            //StringEntity reqEntity = new StringEntity(file.toString());
            request.setEntity( new FileEntity(file, ContentType.APPLICATION_OCTET_STREAM) );

            HttpResponse response = httpclient.execute(request);
            HttpEntity entity = response.getEntity();

            if (entity != null) 
            {
                System.out.println(EntityUtils.toString(entity));
            }
        }
        catch (Exception e)
        {
            System.out.println(e.getMessage());
        }
    }
}

如果您使用IDE,是否尝试调试代码?请求到达服务器,但服务器响应时找不到资源或路径。如果将音频文件移动到-比方说-“C:\\Temp”文件夹或服务器应用程序的子文件夹中,会发生什么情况?我解决了这个问题!服务器无法识别url中的profileID。我写了0,我的档案ID是111f427c-3791-468f-b709-fc**********