UE5 UC++流式请求 || Varest流式调用Coze(但一次性回复,不太推荐)

++文章仅供参考。C++调用的是公司后台的接口,博主未尝试用C++调用Coze的接口,需要补充更多的代码。++

------------

C++

cpp 复制代码
#include "HttpModule.h"
#include "HttpManager.h"
#include "Http.h"

DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FMyCustomEventDelegate, FString, Str1);
public:
	UPROPERTY(BlueprintAssignable, Category = "MyHTTP2")
		FMyCustomEventDelegate StreamingRequestBindEvent;
cpp 复制代码
void UBPC_CJiaJia_streamRequest_V01::StartStreamingRequest(const FString& Url, const FString& Question)
{
	TSharedRef<IHttpRequest> HttpRequest = FHttpModule::Get().CreateRequest();
	HttpRequest->SetVerb("GET"); // 设置请求方法为GET
	HttpRequest->SetURL(Url); // 设置请求的URL
	HttpRequest->SetHeader(TEXT("Content-Type"), TEXT("text/event-stream")); // 设置请求头

	// 请求中返回
	//HttpRequest->OnRequestProgress().BindLambda([this](FHttpRequestPtr Request, int32 BytesSent, int32 BytesReceived) {
	//		FString ContentString = Request->GetResponse()->GetContentAsString();
	//		this->StreamingRequestBindEvent.Broadcast(ContentString);
	//	}
	//);

	// 请求结束返回
	HttpRequest->OnProcessRequestComplete().BindLambda([this](FHttpRequestPtr Request, FHttpResponsePtr Response, bool bWasSuccessful) {
		if (bWasSuccessful) {
			this->StreamingRequestBindEvent.Broadcast(Response->GetContentAsString());
		}
		}
	);

	// 开始处理请求
	HttpRequest->ProcessRequest();
}

请求时,网址+?+参数

Varest

参考网址
扣子 - 开发指南 (coze.cn)创建会话
扣子 - 开发指南 (coze.cn)发起会话

++不太推荐原因是,Varest好像只能做到整段返回++

创建会话

对话

相关推荐
2301_776508725 分钟前
C++与机器学习框架
开发语言·c++·算法
ALex_zry8 分钟前
现代C++设计模式实战:从AIDC项目看工业级代码架构
c++·设计模式·架构
Albertbreak10 分钟前
STL容器内部实现剖析
开发语言·c++·算法
chudonghao11 分钟前
[UE学习笔记][基于源码] 理解 Gameplay
c++·笔记·学习·ue5
2301_7957417913 分钟前
模板编译期机器学习
开发语言·c++·算法
qq_4160187223 分钟前
模板错误消息优化
开发语言·c++·算法
ALex_zry27 分钟前
C++高性能日志与监控系统设计
c++·unity·wpf
Sunshine for you34 分钟前
C++中的对象池模式
开发语言·c++·算法
啊我不会诶1 小时前
求LCA 倍增法
c++·算法·深度优先
暮冬-  Gentle°1 小时前
编译器优化屏障使用
开发语言·c++·算法