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好像只能做到整段返回++

创建会话

对话

相关推荐
lsnm3 分钟前
C++新手项目-JsonRPC框架
开发语言·c++·1024程序员节
给大佬递杯卡布奇诺1 小时前
FFmpeg 基本数据结构 AVPacket分析
数据结构·c++·ffmpeg·音视频
南方的狮子先生1 小时前
【数据结构】从线性表到排序算法详解
开发语言·数据结构·c++·算法·排序算法·1024程序员节
程序猿编码1 小时前
Linux 文件变动监控工具:原理、设计与实用指南(C/C++代码实现)
linux·c语言·c++·深度学习·inotify
好好学习啊天天向上2 小时前
多维c++ vector, vector<pair<int,int>>, vector<vector<pair<int,int>>>示例
开发语言·c++·算法
我狸才不是赔钱货2 小时前
CUDA:通往大规模并行计算的桥梁
c++·人工智能·pytorch
winds~3 小时前
【GUI】本地电脑弹出远程服务器的软件GUI界面
运维·服务器·c++
杨筱毅5 小时前
【穿越Effective C++】条款8:别让异常逃离析构函数——C++异常安全的关键支柱
c++·effective c++
code monkey.5 小时前
【探寻C++之旅】C++ 智能指针完全指南:从原理到实战,彻底告别内存泄漏
c++·c++11·智能指针